0

I am trying to install and test ELMAH for the fist time. I think I have setup everything correctly. I know ELMAH is designed to log unhandled exceptions. I use a standard template MVC 4 application generated by Visual Studio 2012

In a HomeControler class I throw an error without try and catch block

public ActionResult About()
{
    // Throw a test error so that we can see that it is handled by Elmah
    // To test go to the ~/elmah.axd page to see if the error is being logged correctly
    throw new Exception("A test exception for ELMAH");

    return View();
}

In my opinion this an unhandled exception.

Further I use a HandleErrorWithELMAHAttribute class to handle the error. This construct is shown in many ELMAH tutorials originally posted here:

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

The code that bothers me is:

public override void OnException(ExceptionContext context)
{
    base.OnException(context);

    var e = context.Exception;
    if (!context.ExceptionHandled   // if unhandled, will be logged anyhow
        || RaiseErrorSignal(e)      // prefer signaling, if possible
        || IsFiltered(context))     // filtered?
        return;

        LogException(e);
}

In the if statement the property contect.ExceptionHanled is checked. This property is set to true, so the thrown error is not logged.

Can you explain why it is set to true while there is no try-catch.

Best Regards, Sebastian

Community
  • 1
  • 1
Sebastian Widz
  • 1,962
  • 4
  • 26
  • 45
  • The call to base class: base.OnException(context); changes the property value. But how could it be handled? It is the display of custom error page that I have set up in web.config is causing this? ( ) – Sebastian Widz Mar 19 '14 at 21:29
  • 1
    easiest way to install elmah in mvc4 is to use the nuget packages. the packages will add all of the required lines to the web.config Elmah.MVC you can also install Elmah on MS SQL to store error logs in db – ozhug Mar 20 '14 at 00:09

0 Answers0