开发者

How to log all error ocured in site?

开发者 https://www.devze.com 2023-02-06 11:00 出处:网络
I want write an module how log all errors in site. Please guide me.开发者_高级运维Global.asax:

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:

How to log all error ocured in site?

0

精彩评论

暂无评论...
验证码 换一张
取 消