欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#中把日志导出到txt文本的简单实例

程序员文章站 2024-02-21 08:02:34
复制代码 代码如下:///         /// 打日志 &...

复制代码 代码如下:

/// <summary>
        /// 打日志
        /// </summary>
        /// <param name="log"></param>

        //首先还是要using system.io;    
        public void write(arraylist log)
            {
                      //将文件保存在桌面,文件名称为当前时间.txt
                filestream fs = new
                                  filestream("c:\\users\\ailin\\desktop\\" +
                                  datetime.now.tolongtimestring().replace(":", "") + ".txt", filemode.openorcreate, fileaccess.readwrite);
                    streamwriter sw = new streamwriter(fs, encoding.default);
                    foreach( string i in log)
                    {

                            sw.write(i.tostring());

                    }
                     datetime dt1 = datetime.now;
                     sw.writeline();
                     sw.writeline("操作人:cxx");
                     sw.writeline("日期:"+convert.tostring(dt1));
                     sw.flush();
                     sw.close();
            }

            //string ssaveexcelname =
        //"c:\\" + datetime.now.toshortdatestring().replace("-", "") + datetime.now.tolongtimestring().replace(":", "") + ".xls";
         public static arraylist achg_slab_len = new arraylist();
            private void button2_click(object sender, eventargs e)
            {


                    arraylist cx = new arraylist();

                    for (int i = 0; i < ss1.activesheet.rowcount; i++)
                    {
                        for (int j = 0; j < ss1.activesheet.columncount; j++)
                        {
                           cx.add(ss1.activesheet.cells[i, j].text);
                           cx.add("  ");
                        }
                        cx.add("\r\n");

                    }
                    //执行导出日志的操作
                    write(cx);
                    return;

            }

上一篇: Python线程指南详细介绍

下一篇: