Azure Application Insights is a cloud based application monitoring service from Microsoft. You can monitor your applications in all of your environments with Application Insights, including development and production. Microsoft has been shipping Visual Studio with built-in support for Application Insights in Windows. However, Visual Studio for Mac does not yet have the ability to add Application Insights to projects. In this post, I will show you how to add Application Insights telemetry to a .NET Core API using Visual Studio for Mac.

Steps to setup Azure Application Insights telemetry for .NET Core API in Visual Studio for Mac:

  • Create the resource on Azure
  • Manually add package reference to the API project
  • Configure API project with the Instrumentation Key

1. Setup Azure

First of all, create your free Azure account here.

Once you sign up, create a new Resource Group – name it wisely as you cannot change it later.

Navigate to the new resource group and click Add.

Create new resource in azure

In the add resource screen, search for Application Insights and click Create.

Azure will take some time (usually a few seconds) to create the new Application Insights resource. Once it is created, navigate to the resource and find your Instrumentation Key from the right hand side of the screen.

The instrumentation key uniquely identifies the resource you created on Azure. It is also the glue between your applications and Azure. You can use this key with both the server (API) or the browser (front-end).

You will use this instrumentation key later in this post to enable telemetry.

2. Configure Project in Visual Studio for Mac

If your project is open in Visual Studio, close it and open the csproj file in TextEdit or a text editor.

Add the following package reference to an ItemGroup.

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.0"/>

Open the project in Visual Studio for Mac and build. This will install all necessary packages for the project to send telemetry data to Azure.

Next, open the configuration file of your project – usually config.json – and add the Instrumentation Key.

    "ApplicationInsights": {
        "InstrumentationKey": "xxxx-yyyy-zzzz"

If you happen to have multiple environments like staging, you need to create a separate Application Insights resource for each environment. Then, add the instrumentation key in each corresponding configuration file.

Finally, complete the configuration of Application Insights in ConfigureServices inside of Startup.cs:


Application Insights framework reads the whole configuration and interprets your instrumentation key.

3. Monitor Your Application

That’s it! Let’s see some live telemetry.

Startup the project and make a few calls to the API. Head over to the resource in Azure and you’ll see the results live!


We have seen how easy it is to setup Azure Application Insights for .NET Core Web APIs. If you have an Angular app, read my post on how to monitor Angular apps with Azure Application Insights.

Umut Esen

Umut is a certified Microsoft Certified Solutions Developer and has an MSc in Computer Science. He is currently working as a senior software developer in Edinburgh. He is the primary author and the founder of onthecode.

This Post Has One Comment

  1. Khaled Saleh

    Loved it, thanks for sharing!

Leave a Reply