If you're haven't already I would suggest you go read my blog post introducing exception signatures before going any further.
We all have to deal with exceptions. They may not necessarily be bugs but sometimes they are and we're currently left with cataloging our exceptions ourselfs. When it comes to websites tools like ELMAH is a must to even begin to keep track of errors but you still have to rely on your good memory to keep a history of when a particular exception first appeared, how many times it has occurred and if you've fixed it. Ideally we should integrate exceptions into our issue-tracking systems but there's one big problem with that. Automating ticket creation in issue tracking systems currently leaves us without any choice other than to simply insert all exceptions as new tickets and then merge duplicates again relying on our good memory.
Exception signatures is an 8 character long hexadecimal string generated by looking at an exception and all of its inner exceptions. I've implemented this algorithm in a class which I call the ExceptionSignatureBuilder.
Given an exception the ExceptionSignatureBuilder generates a short string generated by looking at the entire chain of the exception. This means that two exceptions that is caused by the same action (ie, someone entered an invalid email address and your data validation layer choked) will get the same exception signature. Think of it as a smart hash function targeted at exceptions.
Generating signatures for your exceptions enables you to integrate exceptions into your issue-tracking system making them first-class citizens in your development environment. Jeff Atwood has a great post about why you should treat your exceptions as todo items.
ViewState exceptions tack on all debug data in their messages instead of properly attaching them to the Data property. The builder identifies this case and disregards dynamic data in the message.
// If you have a website this would probably be the
// Application_Error method
public void UnhandledException(Exception exc)
var esb = new ExceptionSignatureBuilder();
string signature = esb.ToSignatureString();
SendEmail("firstname.lastname@example.org", "Unhandled exception occurred: " + signature", exc.ToString() );
Please note that this is a very naive example. In the real world you would properly format your exception mail, include all Exception.Data information and print out all inner exceptions leading up to your exception.
Check out the download area for the latest published version of the code. It contains the ExceptionSignatureBuilder, a class for hexifying byte arrays, a couple of unit tests and an example program showing off some of the features.
Check out my blog for new releases and general information about this project. If you wan't to filter out blog posts that hasn't got anything to do with this project you can subscribe to the tag exception signatures)
If you find something thats crazy don't hesitate to contact me about it. Patches are gladly accepted under the natural premise that they are released under the same license so that I can include it in the project without worrying about possible legal issues (actually, I'm not that worried but I wan't users of this code to know that they can use the code freely).
While we've used this code at work with great results it probably still contains bugs and one of the reasons I'm posting it here is to get feedback on how to do this, well, better actually. Future versions of the builder may contain breaking changes to the algorithm although I'll avoid it as far as possible.
The exception signature builder is released under the MIT license meaining you can do pretty much whatever you want with it, including using it in proprietary solutions without changing you licensing a bit. Read more on my choice of license at my blog. Special props goes out my and boss that have let me spend some time thinking about this issue and has gracefully agreed to donate all future contributions under the MIT-license.