C#中打日志(导出日志到txt中)_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#中打日志(导出日志到txt中)

C#中打日志(导出日志到txt中)

 2013/10/23 14:55:38  shoneworn  博客园  我要评论(0)
  • 摘要:1///<summary>2///打日志3///</summary>4///<paramname="log"></param>56//首先还是要usingsystem.io;publicvoidWrite(ArrayListlog)7{//将文件保存在桌面,文件名称为当前时间.txt8FileStreamfs=new9FileStream("C:\\Users\\ailin\\Desktop\\"+10DateTime.Now
  • 标签:C#
 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("\r\n"); 43 44 } 45 //执行导出日志的操作 46 Write(cx); 47 return; 48 49 }

 

发表评论
用户名: 匿名