ITmeze - IT world server like cyprus meze

Manually forcing ELMAH to log exception

ITmeze

ELMAH is one of those projects that I use for literally ALL my own projects. It is an easy to implement error-logging component - for ASP.NET (MVC as well). The best thing about it is that it comes with web page that allows you to view all logged errors (even those of 'yellow screen of death'), plus email notification or rss feed. wow ?! Okay, so ELMAH logs all of our unhanded exceptions... What about the case when you 'catch' exception but would still like to log it in ELAM defined medium. To do that, use code sample below:

try {
    throw new ApplicationException("This error has to be logged");
} catch (Exception e) {
    Elmah.ErrorSignal.FromCurrentContext().Raise(e);
}

Such a call is the most proper one and is much safer than calling Elmah.ErrorLog.Default.Log(e). Happy coding!

Tags: [.net] [elmah] [log] [web development]

Copyright 2013 © ITmeze

comments powered by Disqus