[C#] 多用户报错访问日志 →→→→→进入此内容的聊天室

来自 , 2020-04-23, 写在 C#, 查看 98 次.
URL http://www.code666.cn/view/2e74c2cf
  1. protected void Session_Start(Object sender, EventArgs e)
  2.                 {
  3.                        
  4.             LogHelper.LogBasePath = Request.MapPath("/Log/");
  5.         }
  6. protected void Application_Error(Object sender, EventArgs e)
  7.                 {
  8.             if (string.IsNullOrEmpty(LogHelper.LogBasePath))
  9.             {
  10.                 LogHelper.LogBasePath = Request.MapPath("/Log/");
  11.             }
  12.             LogHelper.ExceptonInfoQueue.Enqueue(Server.GetLastError().ToString());
  13.             Response.Redirect("/Error.aspx");
  14.                 }
  15.  
  16.  public class LogHelper
  17.     {
  18.         public static Queue<string> ExceptonInfoQueue = new Queue<string>();
  19.         public static string LogBasePath;
  20.         static LogHelper()
  21.         {
  22.             ThreadPool.QueueUserWorkItem(o =>
  23.             {
  24.                 while (true)
  25.                 {
  26.  
  27.                     if (ExceptonInfoQueue.Count > 0)
  28.                     {
  29.                         string str = ExceptonInfoQueue.Dequeue();
  30.                         //写入错误信息
  31.                         string strFileName = DateTime.Now.ToString(@"\yyyy-MM-dd") + ".txt";
  32.                         string absoluteFileName = Path.Combine(LogBasePath, strFileName);
  33.                         lock (ExceptonInfoQueue)
  34.                         {
  35.                             using (FileStream fs = new FileStream(absoluteFileName, FileMode.Append, FileAccess.Write))
  36.                             {
  37.                                 byte[] data = Encoding.Default.GetBytes(str);
  38.                                 fs.Write(data, 0, data.Length);
  39.                             }
  40.                         }
  41.                     }
  42.  
  43.                 }
  44.             });
  45.         }
  46.     }

回复 "多用户报错访问日志"

这儿你可以回复上面这条便签

captcha