作者romantic1027 (大米)
看板C_Sharp
标题[心得] 写一个简单Debug 日志档
时间Thu May 28 17:56:27 2009
底下C#程式,是一个简单记录LOG的日志档方式:
using System;
using System.IO;//FileStream, Stream Writer and Reader 的 namespace
class MainClass
{
public static void Main()
{
string logFile = "LOGFILE.TXT";//Debug log 档案名称
FileStream fs = new FileStream(logFile, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs); //写档
StreamReader sr = new StreamReader(fs); //读档
sw.WriteLine("AAA");
sw.WriteLine("BBB");
while(sr.Peek() > -1)//将全部档案资料读出
{
Console.WriteLine(sr.ReadLine());
}
sw.Close();
sr.Close();
fs.Close();
}
}
详细内容请至:
http://tw-hkt.blogspot.com/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.59.0.57
1F:→ megaman1206:为啥不直接用内建的Debug类别 05/28 18:15
2F:推 sheauren:enterprise library内的logging直接使用会比较有弹性 05/28 20:59
3F:推 lcloud:nlog不错用... 05/28 21:02
4F:推 tomex:原文是一般的写档,若应用到底层测试ap,可能还得考虑更多喔 05/29 03:56
5F:推 ydchiang:推log4net 05/31 22:47