Quick Tip: How to manually add a log entry in ELMAH

Published Jul 24, 2012 (12 years ago)
Danger icon
The last modifications of this post were around 12 years ago, some information may be outdated!

Quick Tip

I'm a big fan of Elmah (even though I'm still a little more partial to log4Net since it gives you a very quick way of logging all unhandled exceptions in your application. However, sometimes you need to manually add an entry (say within a try/catch block) and fortunately Elmah provides a simple way to do that.

I should have looked through StackOverflow sooner, but here it is. Add this one statement in your catch block (or anywhere else really) and you can get a log entry into Elmah, and let your code continue as planned:

Elmah.ErrorSignal.FromCurrentContext().Raise(ex)

That's all! Happy logging!