Exception handling and logging is something that is usually done at the end of a development project, if at all. If exceptions or information is logged at all, we almost never look at it until a user tells us that something is not working correctly.
This article suggests a method to log issues and to easily be proactive when it comes to quality.
The tool is called Quilt4Net and it works for all .NET environments.
There is one client part that sends data to be logged, using WebAPI to a backend service, where you can watch and analyze. The client is open source and you can download the server and host it yourself.
This setup is particularly good if you have a distributed client, or a server / service without a graphical interface. It also helps greatly for regular websites.
What you get
One of the things the service does is to aggregate exceptions and issues so that you can get a clear overview of what parts and versions of your application have issues.
Another thing it does is to monitor usage of different versions. There is a timeline where you easily can see if clients are updated or not, and when the issues occurred.
In this example you can see that version 126.96.36.199 was used long after that 188.8.131.52 was introduced. The red lines symbolizes exceptions. So, 184.108.40.206 seems to have fewer issues than 220.127.116.11.
Getting startedThere are three easy steps that you have to take to get started.
1. Your application
Get the nuget package Quilt4Net from nuget.org
This can be done from within visual studio.
2. Your code
On application startup. Place the following two lines of code.
Tharga.Quilt4Net.Configuration.ClientToken = "YOUR_TOKEN_HERE";
If this is a service or webservice you will have to provide the startup assembly as a parameter to the BeginRegister method. Otherwise Quilt4Net cannot get hold on what is the initiating assembly.
3. Your ClientToken
Since this component uses a service to register data, it needs to be uniquely identified by the server. Go to https://www.quilt4net.com and register an account. Under the section Initiatives you will find your ClientToken.
Place that token in the code where it sais YOUR_TOKEN_HERE.
Now you are all done, just run the application and look on the site, the usage should be visible there.
The interesting part
Once the setup is complete we will get to the interesting part. Starting to log exceptions. Whenever an exception is catched it can be logged like this.
catch (Exception exception)
It is always good practice to have your custom exceptions contain error messages that are not variable. You know, like the ones you hate, "Object reference not set to an instance of an object.", and you always ask, what object. You should store variable information in the data part of the exception.
This is really the trick to get the exceptions aggregated correctly. So disregarding if you use Quilt4Net or not, this is how you should write your custom exceptions. But dont forget to put your variables in the data-part of the exception, and do not forget to log the data-part, or show it to the user where appropriate.
If you usually log issues to a flat file, to the event log or not at all, this is worth trying. The best way to get a full understand of any developer tool is to try it out. This one is totally free.