记录错误日志

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"/>

错误自动跳转

posted on 2006-01-09 14:06  昊子  阅读(293)  评论(0编辑  收藏  举报

导航