ASP.NET中记录Log到txt文件的方法:

 ErrDescribe)
        {
            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();
            }
        }

 

调用方法:

originalReason);

Log示例:

ApplyForm (2008-11-13 20:13:48)  :
originalReason:5LiA5ZOB6buR5p2/5pyJ6ZmQ5YWs5Y+45LiA5ZOB6buR5p2/5pyJ6Zm

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-09-01
猜你喜欢
  • 2021-10-22
  • 2021-09-14
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案