3

This is the same question as this but for the recent version of application insights 2.2.1

Since updating to the 2.2 version the debug output is filled with AI data even if it is disabled the way it used to be done.

Previously AI was enabled in startup and I could do something like this:

services.AddApplicationInsightsTelemetry(options =>
{
    options.EnableDebugLogger = false;
    options.InstrumentationKey = new ConnectionStringGenerator().GetAITelemetryKey();
});

The new method of adding application insights, per the new VS templates, is to add it in Program.cs like this:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()        
    .UseApplicationInsights(connectionStringGenerator.GetAITelemetryKey())
    .UseSerilog()
    .Build();

In this case there is no construction that takes any options and if I remove the 'UseApplicationInsights' and revert to the original method it makes no difference. Either way I get the output debug window filled wit AI logs.

In fact, even if there is no method to load AI (i.e. I remove both the 'UseApplicationInsights' and 'AddApplicationInsightsTelemetry' I get the logs.

Thanks for any help.

Brian
  • 2,318
  • 3
  • 19
  • 20

2 Answers2

1

You can opt out of telemetry (for debug, for example) by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1.

enter image description here

Jan Palas
  • 1,865
  • 1
  • 23
  • 35
0

Visual Studio is lighting up Application Insights even if you have no code to enable it. You can create an environment variable, ASPNETCORE_PREVENTHOSTINGSTARTUP = True, to prevent Visual Studio from lighting up Application Insights. How to do this? Right click the project in VS, Select Properties.In Debug options add environment variable as shown in below screenshot. enter image description here

cijothomas
  • 2,818
  • 1
  • 13
  • 25
  • That doesn't do anything for me, still flooded with log entries. Ideally I wan't to keep Application Insights data going to its destination but just no clutter the debug log. – Brian Mar 06 '18 at 22:34
  • Can you double-check if you have env vars correctly set? – cijothomas Mar 08 '18 at 04:56
  • I modified my original reply with a screenshot showing how to add the ENV vars. Please try that. – cijothomas Mar 08 '18 at 04:56
  • Thank you very much. That did it, I had done it wrong previously. – Brian Mar 09 '18 at 06:07