Microsoft.ApplicationInsights 错误:InstrumentationKey 不能为空

sov*_*van 5 c# asp.net azure azure-application-insights

我试图使用 Microsoft.ApplicationInsights,我通过 nuget 安装了它。但是当我尝试使用

_telemetryClient.TrackException(ex, new Dictionary<string, string>
                                    {
                                         {"Id", id.ToString()}
                                    }, null);
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息:InstrumentationKey 不能为空。

我已经浏览了URL,但在我的 VS 中看不到任何可用于配置文件的更新菜单(注意:我使用的是 VS 2012 Pro)。

我还尝试使用检测密钥更新配置文件

<ComponentID>{Instrumentation Key}</ComponentID>
Run Code Online (Sandbox Code Playgroud)

但是,这也不起作用。

谢谢。

sov*_*van 1

我仍然没有在配置级别找到任何解决方案。但是,我们可以在初始化 TelemetryClient 对象时提供 Instrumentation Key:

var telemetryClient = new TelemetryClient(new TelemetryConfiguration()
                            {
                                InstrumentationKey = "Key"
                            });
Run Code Online (Sandbox Code Playgroud)

请随时发布答案,我们如何通过配置提供 Instrumentation 密钥。

谢谢。