Elmah ignores exceptions in MVC 3 site

2019-06-05 22:59发布

问题:

I don’t know it this is an issue with ELMAH or ASP.NET MVC3, or just the combination of the two: I’ve configured my MVC 3 website to use ELMAH, but when I enable my “pretty” error page in web.config, ELMAH stops logging exceptions. I used to have just this in my web.config,

<customErrors mode="On" defaultRedirect="/Error.htm" redirectMode="ResponseRewrite"></customErrors>

But at first I didn’t have an Error.cshtml view in my shared folder: ELMAH would log an exception for the missing Error view, when some other exception was thrown. After adding an Error.cshtml view, ELMAH doesn’t log any exceptions anymore.

I’m guessing I need to configure MVC to handle exceptions in a different way, so they’re picked up by ELMAH, and the ASP.NET eventually kicks in and displays the error .htm page. How do I do that? Or am using MVC exceptions and/or ELMAH wrong?

回答1:

Look at this answer directly from the author of Elmah. There is also another answer in the same thread that should give you an alternative approach