Manually logging exceptions with Elmah

If you need to manually log exceptions into Elmah rather than allowing the exception to be thrown there is a built in feature to do that below is a code sample showing you how.

    // log the error
    Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(exception));

The place to put this code is in the catch section of your try catch, very handy! Now you can inform the user of the error rather than showing a generic error page.


Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

One thought on “Manually logging exceptions with Elmah”

  1. Hello,

    Can we made conditional elmah error log manually? ex. If I do not want to apply manual log then without commenting the above line code. Is it possible to avoid ONLY manual elmah error log made by above code line.

    Please let me know if you have any idea on this.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s