欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

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

时间:2021-03-09 10:05:58|栏目:.NET代码|点击:

复制代码 代码如下:

/// <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;

            }

上一篇:c#入门之枚举和结构体使用详解(控制台接收字符串以相反的方向输出)

栏    目:.NET代码

下一篇:C#单例模式(Singleton Pattern)实例教程

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

本文地址:http://www.codeinn.net/misctech/77063.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有