作者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