• C#中打日志导出日志到txt文本


     1         /// <summary>
     2         /// 打日志
     3         /// </summary>
     4         /// <param name="log"></param>
     5 
     6         //首先还是要using system.io;     
    public void Write(ArrayList log) 7 {
    //将文件保存在桌面,文件名称为当前时间.txt
    8 FileStream fs = new 9 FileStream("C:\Users\ailin\Desktop\" + 10 DateTime.Now.ToLongTimeString().Replace(":", "") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); 11 StreamWriter sw = new StreamWriter(fs, Encoding.Default); 12 foreach( string i in log) 13 { 14 15 sw.Write(i.ToString()); 16 17 } 18 DateTime dt1 = DateTime.Now; 19 sw.WriteLine(); 20 sw.WriteLine("操作人:cxx"); 21 sw.WriteLine("日期:"+Convert.ToString(dt1)); 22 sw.Flush(); 23 sw.Close(); 24 } 25 26 //string sSaveExcelName = 27 //"C:\" + DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".xls"; 28 public static ArrayList aChg_Slab_Len = new ArrayList(); 29 private void button2_Click(object sender, EventArgs e) 30 { 31 32 33 ArrayList cx = new ArrayList(); 34 35 for (int i = 0; i < ss1.ActiveSheet.RowCount; i++) 36 { 37 for (int j = 0; j < ss1.ActiveSheet.ColumnCount; j++) 38 { 39 cx.Add(ss1.ActiveSheet.Cells[i, j].Text); 40 cx.Add(" "); 41 } 42 cx.Add(" "); 43 44 } 45 //执行导出日志的操作 46 Write(cx); 47 return; 48 49 }
  • 相关阅读:
    20181020遭遇战
    二分图最大分配
    2019.11.11 洛谷月赛t3
    2019.10.29 CSP%您赛第四场t2
    2019.10.28 CSP%您赛第四场t3
    2019.10.26 CSP%您赛第三场
    2019.10.24 CSP%你赛第二场d1t3
    0080-简单的排序
    0079-简单的循环
    0078-求最大因子
  • 原文地址:https://www.cnblogs.com/shoneworn/p/log.html
Copyright © 2020-2023  润新知