[csharp] view plain copyui
using System; spa
using System.Collections.Generic; .net
using System.Web; 日誌
using System.IO; blog
using System.Text; ip
/// <summary> get
/// Summary description for NetLog string
/// </summary> it
public class NetLog io
{
/// <summary>
/// 寫入日誌到文本文件
/// </summary>
/// <param name="action">動做</param>
/// <param name="strMessage">日誌內容</param>
/// <param name="time">時間</param>
public static void WriteTextLog(string action, string strMessage, DateTime time)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"System\Log\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".System.txt";
StringBuilder str = new StringBuilder();
str.Append("Time: " + time.ToString() + "\r\n");
str.Append("Action: " + action + "\r\n");
str.Append("Message: " + strMessage + "\r\n");
str.Append("-----------------------------------------------------------\r\n\r\n");
StreamWriter sw;
if (!File.Exists(fileFullPath))
{
sw = File.CreateText(fileFullPath);
}
else
{
sw = File.AppendText(fileFullPath);
}
sw.WriteLine(str.ToString());
sw.Close();
}
}