ASP.Net Unhandled Exception Handling: Email exception with MiniDump

For most ASP.Net applications I make I add some code that emails me any unhandled exceptions. This way I immediately know when something has gone wrong with an application. The email contains a lot of useful information, including a MiniDump of the process.

If you are not familiar with it, a MiniDump is a snapshot of the process when it failed which can be loaded into Visual Studio as a “paused project”. You can look at stack trace, locals, execute Immediate commands, etc. You can also use WinDbg to load it with CLR extensions for some in-depth debugging. Very handy.

Using this with Microsoft Azure Cloud apps will ensure proper debugging capability even when you can’t attach a debugger or log on and read the event log.

Also: You don’t have to recreate the exception because you already have a breakpoint where it happened in the code. No more poor bug reports or elusive bugs.

A couple of points before we get on to the code:

  • Uses Nini for config reading, so you need to reference it from your project.
  • Needs write-rights to a folder for MiniDump to work.
  • You have to change: Global.asax and Web.Config
  • You have to create a new class called ApplicationErrorHandler and put the main class in it.

To implement, add this to Global.asax (add a Global.asax if you don’t have it already):

The main class:

And web.config needs some additional info:

1 thought on “ASP.Net Unhandled Exception Handling: Email exception with MiniDump”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Tedds blog

Subscribe now to keep reading and get access to the full archive.

Continue reading