Disable application insights in debug

Running an ASP.NET Core 2.1 web application with Visual Studio 2017 (15.9.2) the "Disable local Application Insights for Asp.Net Core web projects" did not clear up the output in my Debug window.

However adding the following to Configure() in Startup.cs did the job;

if (_env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    TelemetryConfiguration.Active.DisableTelemetry = true;
    TelemetryDebugWriter.IsTracingDisabled = true;
}

Note that the IsTracingDisabled was the key solution, but I left in DisableTelemetry for good measure! Plus having both lines next to one another is helpful when searching for similar references between .NET Framework & .NET Core projects in the same solution.


You can try to use TelemetryConfiguration.DisableTelemetry Property Something like this way..

#if DEBUG
            TelemetryConfiguration.Active.DisableTelemetry = true;
#endif

As an addition to the other solutions I would suggest to add the following let's say to the Global.asax:

protected void Application_Start()
{    
    DisableApplicationInsightsOnDebug();
    // do the other stuff
}

/// <summary>
/// Disables the application insights locally.
/// </summary>
[Conditional("DEBUG")]
private static void DisableApplicationInsightsOnDebug()
{
    TelemetryConfiguration.Active.DisableTelemetry = true;
}

The advantage of this is, that it needs no change to the configs and it works better with some tools like ReSharper which will understand it better than #-directives.


For ASP.NET Core projects the App Insights are ON by default, which actually logs a ton of info into debug window.

To disable it go to "TOOLS --> Options --> Projects and Solutions --> Web Projects" and check "Disable local Application Insights for Asp.Net Core web projects."

Below is the image for disabling local app insights.

Image

For more info on the issue you can see the official github issue here