1void Application_Error(object sender, EventArgs e) 2 { 3 // 在出现未处理的错误时运行的代码 4 Exception objErr = Server.GetLastError().GetBaseException(); //获取错误 5 string err = "Error Caught in Application_Error event\n" + 6 "Error in:" + Request.Url.ToString() + 7 "\nError Message:" + objErr.Message.ToString() + 8 "\nStack Trace:" + objErr.StackTrace.ToString(); 9 //将捕获的错误写入windows的应用程序日志中,可从事件查看器中访问应用程序日志。 10 System.Diagnostics.EventLog.WriteEntry("Test2", err, System.Diagnostics.EventLogEntryType.Error); 11 Server.ClearError(); //清除异常,其他地方不再捕获此异常。 12 }
asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
Wesley13
2021-10-11
1180 0 0
点赞
收藏
评论区
加载中...