ASP.NET中记录Log到txt文件的方法:
{
string tracingFile = "C:/inetpub/wwwroot/log/"; //Server.MapPath("/log/")
if (!System.IO.Directory.Exists(tracingFile))
System.IO.Directory.CreateDirectory(tracingFile);
string fileName = DateTime.Now.ToString("yyyyMMdd") + ".txt";
tracingFile += fileName;
if (tracingFile != String.Empty)
{
System.IO.FileInfo file = new System.IO.FileInfo(tracingFile);
System.IO.StreamWriter debugWriter = new System.IO.StreamWriter(file.Open(System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite));
debugWriter.WriteLine(SPName + " (" + System.DateTime.Now.ToString() + ") " + " :");
debugWriter.WriteLine(ErrDescribe);
debugWriter.WriteLine();
debugWriter.Flush();
debugWriter.Close();
}
}
调用方法:
Log示例:
originalReason:5LiA5ZOB6buR5p2/5pyJ6ZmQ5YWs5Y+45LiA5ZOB6buR5p2/5pyJ6Zm