现在的位置: 首页 > 综合 > 正文

记录错误日志

2011年09月18日 ⁄ 综合 ⁄ 共 966字 ⁄ 字号 评论关闭
using System.Diagnostics;

using System.Diagnostics;

  protected void Application_Error(Object sender, EventArgs e)
  {
   string errMsg = "<link rel=\"stylesheet\" href=\"/ThePhile/Styles/ThePhile.CSS\">";
   errMsg += "<h1>Application Error</h1><hr/>An unexpected error has occurred in this Application. The system " +
    "administrators have been notified. Please feel free to contact us with the information " +
    "surrounding this error.<br/>"+
    "The error occurred in: "+Request.Url.ToString()+"<br/>"+
    "Error Message: <font class=\"ErrorMessage\">"+Server.GetLastError().Message.ToString()+"</font><hr/>"+
    "<b>Stack Trace:</b><br/>"+
    Server.GetLastError().ToString();

   Response.Write( errMsg );

   if (!EventLog.SourceExists("ThePhile.COM"))
   {
    EventLog.CreateEventSource("ThePhile.COM", "Application");
   }
   EventLog.WriteEntry("ThePhile.COM", Server.GetLastError().Message, EventLogEntryType.Error);

   Server.ClearError();
  }

web.config

<customErrors mode="RemoteOnly" defaultRedirect="error.aspx"/>

错误自动跳转

抱歉!评论已关闭.