在Server 发布目录上自动创建一个Log 文件夹.里面按日期生成一个txt 文件记log .
Code
protected void WriteLog(string message)
{
string varAppPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log";
System.IO.Directory.CreateDirectory(varAppPath);
string head = System.DateTime.Now.Hour.ToString() + ":" + System.DateTime.Now.Minute.ToString() + ":" + System.DateTime.Now.Second.ToString() + ":" + System.DateTime.Now.Millisecond.ToString();
string logMessage = head + System.Environment.NewLine + message + System.Environment.NewLine;
string strDate = System.DateTime.Now.ToString("yyyyMMdd");
string strFile = varAppPath + "\\" + strDate + ".log";
StreamWriter SW = new StreamWriter(strFile, true);
SW.WriteLine(logMessage);
SW.Flush();
SW.Close();
}