문제

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?

도움이 되었습니까?

해결책

You can call the Elmah Log explicitly from you ViewPage:

using Elmah;

var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top