simple log
1
public static void WriteLog(string message)
{
try
{
string LogAddress = "";
if (LogAddress == "")
{
LogAddress = Environment.CurrentDirectory + '\\' +
DateTime.Now.Year + '-' +
DateTime.Now.Month + '-' +
DateTime.Now.Day + "_Log.log";
}
StreamWriter fs = new StreamWriter(LogAddress, true);
fs.WriteLine(message);
fs.Close();
}
catch (Exception exlog)
{
Console.WriteLine(exlog.ToString());
}
}
2
public void WriteLog(string content)
{
string LogPath = HttpContext.Current.Server.MapPath(string.Format("~/LOG/Service_{0:yyyyMMdd}.log", DateTime.Today));
string text = string.Format("{0}\t{1}\r\n-------------------------------------------------------------------------------------\r\n", DateTime.Now, content);
CommonFunction.WriteLog(LogPath, text);
}
留言
張貼留言