Application Insights is very powerful out of the box with no further configuration, but it can be tuned for Web API so it’s even more powerful. Suddenly, with a couple extra nugets and a couple configuration tweaks, you can start logging traces within .NET libraries and getting a much more robust sense of what the application is doing – especially when something goes wrong.
This is a snapshot of AI request data by just installing AI without further updates:
This is a snapshot after we tune for Web API:
Notice the difference in data logged and insight into what the application is thinking and doing (obviously, since the API for this example is so simple, it’s relatively benign).
A better example is exception logging.
This is extremely important when trying to figure out a bug that only occurs, for example, in staging and nowhere else. The amount of data you can pull out of AI is pretty astounding. Also, it’s very, very simple.
So, let’s get to it.
Install a couple nugets
To get all this extra data you need two additional nugets:
- Microsoft.AspNet.WebApi.Tracing – Enables ASP.NET Web API tracing to use System.Diagnostics
- Microsoft.ApplicationInsights.TraceListener – A trace listener that will hook into System.Diagnostics output
When you install Microsoft.AspNet.WebApi.Tracing, a little readme.txt will pop up telling you how to configure this additional logging. The short of it is this:
- Open WebApiConfig.cs
- Add “config.EnableSystemDiagnosticsTracing();” in the Register(HttpConfiguration) method (I put it first in the method)
That’s it. As with all of AI, this was extremely painless. You are now collecting a massive amount of more information for your debugging pleasure.