I had been using Application Insights for a while with a Web API project and found it immensely valuable for monitoring how the Web API was performing and discovering any issues in production.
I only recently stumbled across the fact that for ASP.NET projects, the Application Insights telemetry is surfaced and available in your source code within Visual Studio using CodeLens.
I was wondering why I wasn’t seeing this for my project and it seems you only get this magic happening automatically if your project is ASP.NET. My project was a Web API project.
Luckily it didn’t take long to find the answer here:
I followed the steps posted on the comment of this thread. By adding this into an existing Product Group within the project .csproj file.
Note: When substituting values into the above, Resource Group and App Insights are the display name shown in Azure not the ids.
You will need to close and re-open the project in Visual Studio for the changes in the .csproj file to take affect. Once this happens you should be able to right-click on your project in Solution Explorer window and see an Application Insights menu option.
Now you’re all setup, learn more about how to use all this data that is at your fingertips!