【发布时间】:2015-07-17 08:11:44
【问题描述】:
为了在多种环境中支持 Application Insights,我们按照this post 中的建议以编程方式设置Instrumentation Key。
我们将 ApplicationInsights.config 中的 <InstrumentationKey> 留空,而是在 web.config 中添加了一个应用程序设置:
<add key="ApplicationInsightsInstrumentationKey" value="1234-5678-9xxx" />
在 Application_Start 中,我们执行以下操作来设置检测密钥:
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");
但是,这会产生一个异常,提示“必须先初始化 TelemetryChannel,然后才能发送遥测数据”。
谷歌搜索此异常消息不会产生任何结果,但我想在跟踪事件之前还需要一些额外的东西?
【问题讨论】:
-
这可能是因为 ApplicationInsights.config 中的
<InstrumentationKey>元素为空。完全删除了该元素,它现在似乎可以工作了。
标签: c# azure azure-web-app-service azure-application-insights