首页 > 解决方案 > 无法从代码触发 Snapshot Debugger 快照

问题描述

这是一个 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,但没有快照。快照适用于未处理的异常。

第二次发生异常后不应该拍快照吗?

标签: azure-application-insightsvisual-studio-debugging

解决方案


请尝试以下步骤:

1)将您的更改IsEnabledInDeveloperMode为文件。trueApplicationInsights.config

true意味着它将启用快照调试。

<IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>

2)在您的代码之前添加它以检查加载程序集是否有错误。

var _ = typeof(SnapshotCollectorTelemetryProcessor);

3)在您的文件中添加bindredirect web.config

<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)在Extensions --> Manage Extensions下禁用任何与已安装的扩展

b)在工具-->导入和导出设置-->重置所有设置下重置 vs设置

c)删除.vs隐藏文件夹binobj文件夹。


推荐阅读