在 Azure 应用服务中为 .NET 应用启用快照调试器

快照调试器当前支持按 Windows 服务计划在 Azure 应用服务上运行的 ASP.NET 和 ASP.NET Core 应用。

注意

建议在使用 Snapshot Debugger 时在“基本”服务层级或更高服务层级上运行应用程序。 对于大多数应用程序,“免费”和“共享”服务层没有足够的内存或磁盘空间来保存快照。 消耗层级当前不可用于 Snapshot Debugger。

启用快照调试器

预安装 Snapshot Debugger 作为应用程序服务运行时的一部分,但需启用它才能获得适用于应用服务应用的快照。 若要为应用启用 Snapshot Debugger,请遵循下面的说明:

备注

如果使用的是 .NET Core 预览版,或者应用程序引用了 Application Insights SDK(通过依赖程序集直接或间接),请按照为其他环境启用 Snapshot Debugger 的说明进行操作,将 Microsoft.ApplicationInsights.SnapshotCollector NuGet 包包含在应用程序中。

注意

Application Insights Snapshot Debugger 的无代码安装遵循 .NET Core 支持策略。 有关支持的运行时的详细信息,请参阅 .Net Core 支持策略

部署 .NET 应用后:

  1. 转到应用服务的 Azure 控制面板。

  2. 转到“设置”>“Application Insights”页。

    Screenshot showing the Enable App Insights on App Services portal.

  3. 按页面中的说明创建新资源,或者选择现有 App Insights 资源,以便监视应用。

  4. 将 Snapshot Debugger 开关切换到“启用”。

    Screenshot showing how to add App Insights site extension.

  5. 现已使用应用服务应用设置启用了快照调试器。

    Screenshot showing App Setting for Snapshot Debugger.

如果你在运行另一种类型的 Azure 服务,则下面提供了用于在其他受支持平台上启用 Snapshot Debugger 的说明:

为其他云启用 Snapshot Debugger

目前,由世纪互联运营的 Azure 的区域需要通过 Application Insights 连接字符串进行终结点修改。

连接字符串属性 由世纪互联运营的 Azure
SnapshotEndpoint https://snapshot.monitor.azure.cn

若要详细了解其他连接替代,请参阅 Application Insights 文档

禁用快照调试器

若要禁用 Snapshot Debugger,请重复执行启用步骤。 但是,请将 Snapshot Debugger 开关切换到“禁用”。

Azure 资源管理器模板

对于 Azure 应用服务,可在 Azure 资源管理器模板中设置应用设置,以启用 Snapshot Debugger 和 Profiler。 例如:

{
  "apiVersion": "2015-08-01",
  "name": "[parameters('webSiteName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[variables('hostingPlanName')]"
  ],
  "tags": { 
    "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty",
    "displayName": "Website"
  },
  "properties": {
    "name": "[parameters('webSiteName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[parameters('webSiteName')]",
        "[concat('AppInsights', parameters('webSiteName'))]"
      ],
      "properties": {
        "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', concat('AppInsights', parameters('webSiteName'))), '2014-04-01').InstrumentationKey]",
        "APPINSIGHTS_PROFILERFEATURE_VERSION": "1.0.0",
        "APPINSIGHTS_SNAPSHOTFEATURE_VERSION": "1.0.0",
        "DiagnosticServices_EXTENSION_VERSION": "~3",
        "ApplicationInsightsAgent_EXTENSION_VERSION": "~2"
      }
    }
  ]
},

不支持的场景

可以在下面找到不支持 Snapshot Collector 的场景:

方案 副作用 建议
在应用程序 (.csproj) 中直接使用 Snapshot Collector SDK 并且已启用高级选项“互操作”。 本地 Application Insights SDK(包括 Snapshot Collector 遥测)将丢失,并且将没有快照可用。
应用程序在启动 System.ArgumentException: telemetryProcessorTypedoes not implement ITelemetryProcessor. 时可能会崩溃
详细了解 Application Insights 功能“互操作”。
如果使用高级选项“互操作”,请使用无代码 Snapshot Collector 注入(通过 Azure 门户启用)。

后续步骤

  • 为应用程序生成可触发异常的流量。 然后等待 10 到 15 分钟,这样快照就会发送到 Application Insights 实例。
  • 请参见 Azure 门户中的快照
  • 排查 Snapshot Debugger 问题时如需帮助,请参阅 Snapshot Debugger 故障排除