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
Alberto Rivelli Sep 29 '15 at 0:27 2015-09-29 00:27
source share