favicon

Sending filtered exceptions to Airbrake using Elmah

I love Elmah and it's probably the one library that has been a staple of my development for as long as I can remember. I also use an excellent code hosting service called Codebase for storing my repositories and handling issue tracking. One of the services that Codebase offer is an Airbrake-based exception management tool, so it seemed sensible that given that my source code and issues are managed in Codebase, I should report any of my exceptions there so that they could be tracked and also linked to tickets.

There are several .Net Airbrake nuget packages available but they all have the same restriction in that they don't have the ability to filter out unwanted errors, e.g. 404. But Elmah does and I'm already using Elmah to email me error notifications it made sense to combine the two.

This is much easier than it might seem since Elmah uses its ErrorLogModule to handle the reporting of exceptions and this can be inherited from to create a custom HttpModule.

So my code is basic:

I have also installed an Airbrake nuget package called SharpBrake to handle the messaging, and so not to reinvent the wheel. This is used in the single call, e.SendToAirbrake();

In my website's web.config, I then:

  • Update the Elmah configuration to replace the ErrorLogModule reference with my CustomModule;
  • Register a reference to the HttpModule; and;
  • Add the SharpBrake appSettings.

And that's it. Now I get exception notifications to my Airbrake-based management tool courtesy of Elmah and it's exception filtering.

The full code is here.

Tags: Elmah , Exception handling , Airbrake
Published: 19 January 2016

Return to top