While Rollbar doesn’t have an official client, they suggest the open source RollbarSharp project.
Installing it is super easy:
Install Library from NuGet
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
1 2 3 4
RollbarSharp can automatically read these keys out of the file and you’ll be on your way.
Add an ExceptionFilter to record the errors
Following along with the installation instructions on GitHub, next add an
IExceptionFilter to your project.
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9
Test it out
Can you believe it? That’s all it takes! Create an action that throws an exception and give it a test.
1 2 3 4 5 6 7 8 9 10 11 12