Click here to Skip to main content
Click here to Skip to main content

How to use exceptions to your advantage with Quilt4Net

, 20 May 2014
Rate this:
Please Sign up or sign in to vote.
What do you do with your exceptions? Hide them in a log and never look at them? Here is a better idea!

Introduction

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.

Background

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 3.1.14.0 was used long after that 3.1.15.0 was introduced. The red lines symbolizes exceptions. So, 3.1.14.0 seems to have fewer issues than 3.1.15.0.

Getting started

There are three easy steps that you have to take to get started.

1. Your application

Get the nuget package Quilt4Net from nuget.org
https://www.nuget.org/packages/Tharga.Quilt4Net/

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";
Tharga.Quilt4Net.Session.BeginRegister();

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)
{
    Tharga.Quilt4Net.Issue.BeginRegister(exception);
    throw;
}  

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.

Finally

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Daniel Bohlin

Sweden Sweden
I have been a developer for over 15 years, mainly with C++ and C#.

Comments and Discussions

 
GeneralReally good after the update. [modified] PinmemberPoxet22-May-14 7:34 
GeneralMy vote of 1 PinmemberLuigiCarrione20-May-14 19:02 
GeneralMy vote of 1 PinmemberGordoFabulous20-May-14 8:22 
GeneralMy vote of 1 PinmemberAndré Pereira20-May-14 5:24 
GeneralMy vote of 2 PinmemberPhilip Liebscher19-May-14 9:02 
GeneralRe: My vote of 2 PinmemberDaniel Bohlin19-May-14 9:45 
QuestionThoughts PinmemberDewey19-May-14 7:05 
AnswerRe: Thoughts PinmemberDaniel Bohlin19-May-14 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 21 May 2014
Article Copyright 2014 by Daniel Bohlin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid