I want write an module how log all errors in site. Please guide me.开发者_高级运维
Global.asax:
<%@ Application Inherits="MyProj.Global" %>
Global.asax.cs:
namespace MyProj
{
public class Global : HttpApplication
{
protected virtual void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
}
}
}
Take a look at the Application_Error event, that can be put in a Global.asax file (more info here and here).
Basically that event is called every time there is an unhandled exception in your application code - one more reason not to handle exceptions that you can't manage.
Don't write your own but use an existing one like log4net or NLog
Suggest looking at the little-known free ELMAH error reporting module for ASP.NET.
Very cool:
精彩评论