Elmah is not logging NullReference exception

181 Views Asked by At

Good afternoon,

in my project is installed elmah framework to logging exceptions. On the localhost it works fine, but when I deploy it to production it stops logging null reference exceptions. All others exceptions are logged (or I didn't find out next which is not logged). I have set logging into SqlServer.

I can't find out what is wrong, can someone give me advice please? (How I said it loggs all exceptions what I fired but only this one is never caught)

Thank you

1

There are 1 best solutions below

0
On BEST ANSWER

Well, Thomas Ardal answered right.

Problem was in the FilterConfig.cs file. Because in default settings it didn't want log any 500 errors, dangerous requests, null reference exceptions etc, i have added this lines:

public class ElmahHandleErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        if(filterContext.Exception is HttpRequestValidationException)
        {
            ErrorLog.GetDefault(HttpContext.Current).Log(new Error(filterContext.Exception));
        }
    }
}

and added this line to the RegisterGlobalFilters method on the first place.

filters.Add(new ElmahHandleErrorAttribute());

After that it started log some exceptions but not all. Solution is that I remove if condition and catch everything. So if anyone will have similar problem, be sure, that problem will be somewhere in filters...