1

We have an ASP.NET webforms app that has try/catch blocks all throughout. In the catch block, it calls a method that sends an email containing limited information about the error thrown.

We want to implement ELMAH in this app, but ELMAH only works with unhandled exceptions (based on my experiences, at least). What I would like to do is, instead of removing all the try/catch blocks from the app, replace the code within the method that sends the email with a call to ELMAH that will force ELMAH to send an email as if the exception were unhandled. It would look just like the regular email, complete with stack trace, authenticated user, referring URL, etc.

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206

1 Answers1

2

If you handle the exception, ELMAH will not receive it.

ELMAH is not designed to be a full logging framework but to work alongside one, such a log4net.

Instead of trying to force ELMAH into this role, consider using a dedicated logging framework for your handled exceptions.

You can signal ELMAH from your handling code if you really need to, as described in this answer to does elmah handle caught exceptions as well:

ErrorSignal.FromCurrentContext().Raise(ex);
Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Good answer. Glad you edited that in. My initial idea was to throw the exception, but using ELMAH's construct is better. It's worth noting that the above is in the Elmah namespace. – oscilatingcretin Jan 13 '12 at 14:06
  • @oscilatingcretin - Fair point, though from context that should be clear. – Oded Jan 13 '12 at 14:07
  • I noticed that using the above .Raise() method doesn't trigger a redirect to my custom error page. Calling `Throw ex` does, but the stack trace ELMAH produces is somewhat obfuscated. Is there any way to get ELMAH's .Raise() method to trigger the redirect? – oscilatingcretin Jan 13 '12 at 14:40
  • @oscilatingcretin - I don't believe so. – Oded Jan 13 '12 at 16:29