In my previous blog, I explained in general what you can do with Application Insights. I also gave a short introduction how you use the API to track events and trace information. In this blog, I'll explain how exceptions are tracked and how Application Insights can be helpful for solving exceptions. Better said how you can actively monitor your application to discover and solve exceptions before your customer reports them. It's always a pain to solve a reported issue without a detailed description. Probably you'll end up trying some things yourself until you can reproduce the issue. Application Insights to the rescue! Application Insights collects a lot of information about exceptions, but sometimes you'll notice you miss some information. By using the API to track extra information, you definitely will have a great tool that will provide you all the information you need. Based on some examples I'll guide you to through the possibilities.

Later in this blog, I'll explain based on an example how you use Application Insights for solving exceptions.

Track exceptions

All requests that throw an exception are tracked by Application Insights. You don't have to configure anything for that. When the NuGet packages are installed, you'll notice that the AiHandleErrorAttribute class is placed in the ErrorHandler folder. This class can be used in two ways. Since this class inherits from HandleErrorAttribute you can decorate a controller with this attribute. Each time an exception is thrown this class attribute will track the exception. You can also use the AiHandleErrorAttribute as exception filter since this class also inherits from IExceptionFilter. So if you want to use this class for all controllers, you can register it as an MVC exception filter.