How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?

前端 未结 8 1961
后悔当初
后悔当初 2020-11-22 02:53

I am trying to use ELMAH to log errors in my ASP.NET MVC application, however when I use the [HandleError] attribute on my controllers ELMAH doesn\'t log any errors when the

8条回答
  •  无人及你
    2020-11-22 03:04

    For me it was very important to get email logging working. After some time I discover that this need only 2 lines of code more in Atif example.

    public class HandleErrorWithElmahAttribute : HandleErrorAttribute
    {
        static ElmahMVCMailModule error_mail_log = new ElmahMVCMailModule();
    
        public override void OnException(ExceptionContext context)
        {
            error_mail_log.Init(HttpContext.Current.ApplicationInstance);
            [...]
        }
        [...]
    }
    

    I hope this will help someone :)

提交回复
热议问题