While Rollbar doesn’t have an official client, they suggest the open source RollbarSharp project.
First, you need the bits. Get them with the NuGet package manager, or just run
install-package RollbarSharp in your package manager console.
RollbarSharp needs to your API key and your environment string (
production, etc). The best way to set that up is a couple entries in the good
RollbarSharp can automatically read these keys out of the file and you’ll be on your way.
Following along with the installation instructions on GitHub, next add an
IExceptionFilter to your project.
This class will ignore Exceptions that are treated as Handled, but will send all others to Rollbar using the RollbarSharp library. Easy-peasy.
RollbarSharp’s GitHub page suggests adding an instance of this class to
GlobalFilters.Filters, but I found this problematic, especially on azure.
Azure Websites seem to have a build in custom error page handler that steals
the exceptions from flowing to Rollbar.
I seriously thrashed on this for a couple hours and a dozen experimental commits, but finally figured out how it all works.
This will work eventually… pic.twitter.com/0f1t2djUMe— Matt Burke ☧ (@akatakritos) July 20, 2014
In MVC5, there’s a nice
FilterConfig class already written for you, which
adds the offending
HandleErrorAttribute that steals your exceptions. Exceptions
flow through the filters and are possibly handled and canceled from further
processing. This seems to be the case with the
HandleErrorAttribute: once it
RollbarExceptionFilter will not get a chance to do its work.
Instead of stuffing the RollbarExceptionFilter into the global filters list,
FilterConfig class to add it before the
Can you believe it? That’s all it takes! Create an action that throws an exception and give it a test.