Question

I got the Rescue attribute working. It properly serves up the DefaultError view when there is an unhandled exception.

However, these exceptions will not get logged or emailed. This SO question is answered by Atif Aziz and it looks pretty solid, but it applies to the built-in HandleErrorAttribute, which Rescue replaces, right? How do I get that to work with Rescue? I want to make sure that if an unhandled exception arises, that the user gets served up the view specified with the Rescue attribute, but the exception is still properly logged, and viewable with elmah.axd.

Update:

var currentContext = HttpContext.Current;
Elmah.ErrorSignal.FromContext(currentContext).Raise(ViewData.Model.Exception, currentContext);

I added the above to my view and it properly logs and emails errors now. However, it doesn't seem like doing this in the view is the right thing. Does anyone have a better idea?

Was it helpful?

Solution

You can call the Elmah Log explicitly from you ViewPage:

using Elmah;

var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top