In order to support Application Insights in several environments, we programmatically install the Tool Key, as recommended in this post .
We left the <InstrumentationKey> in ApplicationInsights.config empty and instead added the application settings to web.config :
<add key="ApplicationInsightsInstrumentationKey" value="1234-5678-9xxx" />
At Application_Start, we do the following to set the toolkit key:
var instrumentationKey = ConfigurationManager.AppSettings["ApplicationInsightsInstrumentationKey"]; if (string.IsNullOrWhiteSpace(instrumentationKey)) { throw new ConfigurationErrorsException("Missing app setting 'ApplicationInsightsInstrumentationKey' used for Application Insights"); } TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey; new TelemetryClient().TrackEvent("Application started");
However, this raises an exception: "The TelemetryChannel must be initialized before it can send telemetry .
Inclusion of this exception message yields nothing, but I assume there is something extra needed to track events?
source share