views:

124

answers:

1

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?

A: 

You can call the Elmah Log explicitly from you ViewPage:

using Elmah;

var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));
Shay Erlichmen
That didn't work for email, but it got me on the right track and I figured it out, updating my question with my current solution. It still doesn't seem ideal, however.
Chris