Azure Tips and Tricks Part 32 - Using Application Insights with Azure App Service

2 minute read


Most folks aren’t aware of how powerful the Azure platform really is. As I’ve been presenting topics on Azure, I’ve had many people say, “How did you do that?” So I’ll be documenting my tips and tricks for Azure in these posts.

The Complete List of Azure Tips and Tricks

Available Now!

Using Application Insights with Azure App Service

Application Insights is a simple way to detect and diagnose exceptions and application performance issues in your web apps and web services. In this blog post, I’ll walk you through adding it to an ASP.NET MVC application.

In order to take advantage of this, you’ll need to log into your Azure account and go to your App Service that you created and look under Monitoring then you will see Application Insights. Open it and create a new resource and press OK as shown below.

It will bring you to a page with no data but will present you with the following prompt:

You’ll see that you can automatically instrument your ASP.NET app with a restart. Yes, please. Go ahead, and click on the orange banner to restart your app.

Once complete, go and visit your app and refresh a couple of times and then go back and take a look at the live stream. I’ve included a sample below:

It is working as expected, but let’s add an error into our application. Go to your appname/Controllers/HomeController.cs and add the following code:

public ActionResult ThrowNewError()
  throw new InvalidOperationException("The app just threw an error!"); 

You’ll need to go back to your site and depending on where you placed it, you can invoke the code by going to * If you switch back over to Application Insights, then you’ll see the errors are being reported.

You can drill deeper down by clicking on Open in Application Insights. From here you can see how many Failed Request were reported.

You can even drill down on what URL was called to trigger the error.

If you add Application Insights to your Visual Studio project by right-clicking the project and then adding Configure Application Insights, then you can add code to collect exception telemetry. You can learn more about that by clicking here.

That is really just the tip of the iceberg with Application Insights. I’d encourage you to learn more about it by visiting their page.

Want more Azure Tips and Tricks?

If you’d like to learn more Azure Tips and Tricks, then follow me on twitter or stay tuned to this blog! I’d also love to hear your tips and tricks for working in Azure, just leave a comment below.

Leave a Comment