问题描述
这是在Visual Studio解决方案中,带有一个将.NET Framework 4.6作为UI项目的Asp.Net MVC应用程序,以及其他几个C#类库项目。
我们将Application Insights Nuget程序包(包括Snapshot Collector程序包)应用于我们希望跟踪的解决方案中的所有项目。所有的Nuget软件包都使用最新版本。
要从代码中触发快照,我将引发如下异常:
try
{
throw new Exception("This is an AI test exception");
}
catch (Exception ex)
{
var ai = new TelemetryClient();
var props = new Dictionary<string,string> { { "Property1","A test property value" } };
ai.TrackException(ex,props);
}
MVC项目的ApplicationInsights.config配置如下
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor,Microsoft.ApplicationInsights.SnapshotCollector">
<IsEnabledindeveloperMode>false</IsEnabledindeveloperMode>
<HandleUntrackedExceptions>true</HandleUntrackedExceptions>
<ThresholdForSnapshotting>1</ThresholdForSnapshotting>
<ProblemCounterResetInterval>2.00:00:00</ProblemCounterResetInterval> <!--2 days-->
</Add>
</TelemetryProcessors>
我将应用程序发布到Azure,并通过浏览该应用程序多次调用该异常。
此设置导致将异常记录到Application Insights中,但没有快照。对于未处理的异常,快照可以正常工作。
第二次发生异常后,是否应该拍摄快照?
解决方法
请尝试以下步骤:
1)将IsEnabledInDeveloperMode
文件中的true
更改为ApplicationInsights.config
。
true
表示它将启用快照调试。
<IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>
2)在代码之前添加此代码,以检查加载程序集是否存在错误。
var _ = typeof(SnapshotCollectorTelemetryProcessor);
3)在您的web.config
文件中添加bindredirect:
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="xxxxx" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.15.0.44797" newVersion="2.15.0.44797"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights.SnapshotCollector" publicKeyToken="xxxx" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.7.0" newVersion="1.3.7.0" />
</dependentAssembly>
通常,这些活动将位于%temp%
文件夹中。
如果不起作用,
a)在扩展-> 管理扩展
下禁用任何已安装的扩展b)相对于工具下的设置进行重置–> 导入和导出设置-> 重置所有设置
c)删除.vs
隐藏文件夹,bin
和obj
文件夹。