C# Microsoft.ApplicationInsights错误:InstrumentationKey不能为空

C# Microsoft.ApplicationInsights错误:InstrumentationKey不能为空,c#,asp.net,azure,azure-application-insights,C#,Asp.net,Azure,Azure Application Insights,我尝试使用Microsoft.ApplicationInsights,并通过nuget安装了相同的程序。但是当我尝试使用 _telemetryClient.TrackException(ex, new Dictionary<string, string> { {"Id", id.ToString()}

我尝试使用Microsoft.ApplicationInsights,并通过nuget安装了相同的程序。但是当我尝试使用

_telemetryClient.TrackException(ex, new Dictionary<string, string>
                                    {
                                         {"Id", id.ToString()}
                                    }, null);
\u遥测客户端.TrackException(例如,新字典
{
{“Id”,Id.ToString()}
},空);
我得到一个错误,说: InstrumentationKey不能为空

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

我还尝试过用插入键更新配置文件

<ComponentID>{Instrumentation Key}</ComponentID>
{Instrumentation Key}
但是,这也不起作用


谢谢。

我还没有在配置级别找到任何解决方案。但是,我们可以在初始化遥测客户端对象时提供检测密钥:

var telemetryClient = new TelemetryClient(new TelemetryConfiguration()
                            {
                                InstrumentationKey = "Key"
                            });
请毫不犹豫地发布一个答案,我们如何通过配置提供检测密钥


谢谢。

我假设您已经添加了.11或更高版本的Application Insights SDK。如果是这样,请在将Application Insights SDK添加到项目后,将Instrumentation密钥添加到applicationinsights.config文件,如下所示:

</TelemetryInitializers>
<InstrumentationKey>your-guid-goes-ere</InstrumentationKey>
</ApplicationInsights>

你的guid在这里

您是手动下载nuget,还是通过UI向项目中添加AppInsights来获得它? 当用户试图手动添加单个熔核时,我们已经看到了这个问题

最简单的恢复方法是通过右键单击项目并选择更新应用程序洞察来添加完整的AppInsights支持-它将要求您创建新的AI资源或指向现有AI资源,并为您创建检测密钥


但是,您需要使用VS 2013,以便将VS集成用于应用程序洞察。

在您的配置方法中使用以下代码

Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = key;

在我的情况下,我只需要将我的IP添加到Azure数据库防火墙-在我们得到关于防火墙的解释性错误之前,
InstrumentationKey
失败,因此可能会令人困惑。

是的,我通过nuget软件包安装了AppInsights。这似乎是VS2012的一个问题。当我们尝试使用VS2013时,一切正常。这个解决方案对我不起作用,我在遥测初始化器中获得了NRE。我不得不使用:TelemetryConfiguration.Active.InstrumentationKey=“guid”奇怪的是,当使用
TelemetryConfiguration
构造函数传递密钥时,我遇到了这个错误,但是当按照上面的答案进行设置时,它可以正常工作。