Turn off application search in debugging

How can I automatically turn off application information when using a debug configuration and enable it only on release?
Is it possible to do this without creating another tool key for debugging only?

I have trackevent expressions scattered throughout the code, and turning them on inside a debug preprocessor check is not an ideal solution.

My current solution is to set the Build Action the ApplicationInsights.config file to None so that it is not copied to the project output directory, but this is not a process that can be automated based on the active configuration assembly.

There is a developer mode, but it needs to be changed manually (if it was possible to conditionally install the configuration file, also devastating the problem with the tool key). See http://apmtips.com/blog/2015/02/02/developer-mode/

Link: http://blogs.msdn.com/b/visualstudioalm/archive/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions.aspx

+82
c # azure-application-insights
Aug 17 '15 at 18:40
source share
12 answers

As explained in the question of not deploying or deploying ApplicationInsights.config events without the <instrumentationkey>key</instrumentationkey> from generating the events. Then you can put the toolkit key in the code (only on release in my case)

 #if !DEBUG Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "instrumentation key"; #endif 

Each TelemetryClient created after this call will have the correct key and will track events, so you do not have to change the code in all places. Do not call the method above or leave this parameter empty, events will be blocked because the key is not configured.

Basically, the ApplicationInsights.config file overrides any code that sets the toolkit key by removing the <instrumentationkey>key</instrumentationkey> inside it, allowing you to use the code to configure the key. If you delete the file completely, it will not work.

Here is the confirmation: "If you want to install the key dynamically - for example, if you want to send the results from your application to different resources, you can omit the key from the configuration file and instead install it in the code."

Link: https://azure.microsoft.com/en-us/documentation/articles/app-insights-configuration-with-applicationinsights-config/#_instrumentationkey

+19
Sep 29 '15 at 0:27
source share

You can try using the TelemetryConfiguration.DisableTelemetry Property Something like this.

 #if DEBUG TelemetryConfiguration.Active.DisableTelemetry = true; #endif 
+58
Aug 18 '15 at 13:37
source share

As a complement to other solutions, I would suggest adding the following words: 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 does not need configuration changes, and it works better with some tools, such as ReSharper, which will better understand it than # -directives.

+53
Aug 14 '16 at 11:55 on
source share

For ASP.NET projects, Core App Insights are enabled by default, which actually writes tons of information to the debug window.

To disable it, go to "TOOLS → Options → Projects and Solutions → Web Projects" and check the box "Disable local application information for Asp.Net Core web projects."

The image below is for disabling local application information.

Image

For more information about the issue, you can see the official release of GitHub here.

+20
Mar 16 '18 at 7:32
source share

I decided to use both approaches. I moved InstrumentationKey to Web.config and it will be replaced by a conversion from Web.Release.config or Web.Debug.config . (Remember to remove it from the ApplicationInsights.config file). Then I called this method from Application_Start()

 public static void RegisterTelemetryInstrumentationKey() { if (string.IsNullOrWhiteSpace(WebConfigurationManager.AppSettings["TelemetryInstrumentationKey"]) { TelemetryConfiguration.Active.DisableTelemetry = true; } else { TelemetryConfiguration.Active.InstrumentationKey = AppSettings.TelemetryInstrumentationKey; } } 
+12
May 7 '16 at 16:33
source share

I had the same problem.

We wanted to control the configuration in web.config, so we added the DisableAITelemetry key to our application settings:

  <appSettings> <add key="DisableAITelemetry" value="true" /> </appSettings> 

With live and demo builds, we will not include the value (so that it is false by default).

Then we could solve this problem by adding the following:

 bool disable; string disableAiTelemetry = ConfigurationManager.AppSettings["DisableAITelemetry"]; bool.TryParse(disableAiTelemetry, out disable); TelemetryConfiguration.Active.DisableTelemetry = disable; 
+10
May 04 '16 at
source share

In an ASP.NET Core application, you can add the following to Startus.cs to disable Application Insights in the development environment:

 if (env.IsDevelopment()) { TelemetryConfiguration.Active.DisableTelemetry = true; } 

Add this to the constructor immediately after the builder.AddApplicationInsightsSettings(); command builder.AddApplicationInsightsSettings(); and you will no longer see AI logs clogging up the debug console.

+9
Aug 2 '17 at 13:35 on
source share

A bit different than some other solutions. Put this in your global.asax:

 Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryDebugWriter.IsTracingDisabled = Debugger.IsAttached; 

It will disconnect the debug output from the application when running under the debugger, but will enable it in scripts Ctrl + F5 and debug builds published for server testing

+7
Jul 04 '17 at 15:21
source share

We found that the easiest way to prevent it from being tracked in the debug log is as simple as:

 Extensibility.Implementation.TelemetryDebugWriter.IsTracingDisabled = True 
+4
Jun 23 '17 at 14:27
source share

When I started the ASP.NET Core 2.1 web application with Visual Studio 2017 (15.9.2) "Disabling local application information for Asp.Net Core web projects", I could not clear 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 IsTracingDisabled was the key solution , but I left in DisableTelemetry for a good measure! In addition, having both lines next to each other is useful when looking for similar links between .NET Framework and .NET Core projects in the same solution.

+4
Nov 22 '18 at 6:03
source share

Microsoft.ApplicationInsights.AspNetCore Version 2.1

 services.AddApplicationInsightsTelemetry(options => { options.EnableDebugLogger = false; }); 
+3
Aug 02 '17 at 20:52 on
source share
  public void Configure(IApplicationBuilder app, IHostingEnvironment env) { #region Disable Application Insights debug informations #if DEBUG TelemetryConfiguration.Active.DisableTelemetry = true; TelemetryDebugWriter.IsTracingDisabled = true; #endif #endregion //... } 
0
Mar 28 '19 at 9:21
source share



All Articles