Thom Thom - 1 year ago 157
ASP.NET (C#) Question

Cannot connect ASP.NET Core web app with Application Insights

I have ASP.NET Core MVC project (one of these new-fangled things that starts up as a console app) in Visual Studio Community 2015 Update 3 hosted on Azure App Services. I'm trying to set up Application Insights, mostly because I'd like to capture diagnostic traces with the

but the other features are useful too. I have yet to stumble upon the correct configuration to get anything at all to show up in the Azure Portal.

I added Application Insights support to my project using the Visual Studio extension. However, and this seems to be where things start going wrong, it does not create an
. It adds some DLLs, and puts the
in my app settings file, and I have manually added some more assemblies via NuGet, including
. Publishing at this point results in no metrics being enabled in the Azure Portal, and the Live Stream telling me Not available: your app is offline or using an older SDK.

I have tried both 2.1.0 and a 2.2.0 beta. I have tried deleting all the Application Insights stuff, reinstalling the extension and starting again. I have also tried to skip using the extension, manually adding
et al, which some google results implied should create the config file also, but with no luck. I have downloaded other people's
files from the web and attempted to make them sensible for my environment. At no point has anything ever worked in the Application Insights part of the portal.

What extra steps should the extension have taken in addition to creating a config file? Do I need to add code to my
? Most of the documentation just seems to take for granted that the initial setup works.

Answer Source

You need to modify your Startup.cs, considering that your InstrumentationKey is on the appsettings.json:

public void ConfigureServices(IServiceCollection services)
    /*Simple Mvc web app*/


public void Configure(IApplicationBuilder app, IHostingEnvironment env, IAntiforgery antiforgery)
    /*This should be before UseMvc*/
    /*This could be after UseMvc*/

It's important that the app.UseApplicationInsightsRequestTelemetry() is before app.UseMvc().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download