您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Azure 应用服务中为 .NET 应用启用快照调试器Enable Snapshot Debugger for .NET apps in Azure App Service

Snapshot Debugger 当前支持在 Windows 服务计划的 Azure App Service 上运行的 ASP.NET 和 ASP.NET Core 应用。Snapshot Debugger currently supports ASP.NET and ASP.NET Core apps that are running on Azure App Service on Windows service plans.

建议你在使用快照调试程序时,在 "基本" 服务层或更高版本上运行应用程序。We recommend you run your application on the Basic service tier or higher when using snapshot debugger. 对于大多数应用程序,“免费”和“共享”服务层没有足够的内存或磁盘空间来保存快照。For most applications, the Free and Shared service tiers don't have enough memory or disk space to save snapshots.

启用 Snapshot DebuggerEnable Snapshot Debugger

若要为应用启用快照调试器,请遵循下面的说明。To enable Snapshot Debugger for an app, follow the instructions below.

如果你在运行另一种类型的 Azure 服务,则下面提供了用于在其他受支持平台上启用 Snapshot Debugger 的说明:If you're running a different type of Azure service, here are instructions for enabling Snapshot Debugger on other supported platforms:

备注

如果你使用的是 .NET Core 的预览版本,或你的应用程序通过依赖程序集直接或间接引用 Application Insights SDK,请按照为 其他环境启用 Snapshot Debugger 的 说明,将 microsoft.applicationinsights.snapshotcollector NuGet 包添加到应用程序,然后完成下面的说明。If you're using a preview version of .NET Core, or your application references Application Insights SDK, directly or indirectly via a dependent assembly, follow the instructions for Enable Snapshot Debugger for other environments to include the Microsoft.ApplicationInsights.SnapshotCollector NuGet package with the application, and then complete the rest of the instructions below.

Application Insights Snapshot Debugger 的无代码置备安装遵循 .NET Core 支持策略。Codeless installation of Application Insights Snapshot Debugger follows the .NET Core support policy. 有关支持的运行时的详细信息,请参阅 .Net Core 支持策略For more information about supported runtimes, see .NET Core Support Policy.

预安装 Snapshot Debugger 作为应用程序服务运行时的一部分,但需启用它才能获得适用于应用服务应用的快照。Snapshot Debugger is pre-installed as part of the App Services runtime, but you need to turn it on to get snapshots for your App Service app.

部署应用后,请按照以下步骤启用 Snapshot Debugger:Once you've deployed an app, follow the steps below to enable the snapshot debugger:

  1. 导航到应用服务的 Azure 控制面板。Navigate to the Azure control panel for your App Service.

  2. 转到“设置”>“Application Insights”页面。Go to the Settings > Application Insights page.

    在应用服务门户上启用 App Insights

  3. 按页面中的说明创建新资源,或者选择现有 App Insights 资源,以便监视应用。Either follow the instructions on the page to create a new resource or select an existing App Insights resource to monitor your app. 另外,请确保快照调试器的两个开关都为“开” 。Also make sure both switches for Snapshot Debugger are On.

    添加 App Insights 站点扩展

  4. 现已使用应用服务应用设置启用了快照调试器。Snapshot Debugger is now enabled using an App Services App Setting.

    快照调试器的应用设置

禁用快照调试器Disable Snapshot Debugger

执行与 启用快照调试器 相同的步骤,但将快照调试器的两个开关都切换到“关” 。Follow the same steps as for Enable Snapshot Debugger, but switch both switches for Snapshot Debugger to Off.

建议对所有应用启用 Snapshot Debugger,以简化应用程序异常的诊断。We recommend you have Snapshot Debugger enabled on all your apps to ease diagnostics of application exceptions.

Azure Resource Manager 模板Azure Resource Manager template

对于 Azure 应用服务,可在 Azure 资源管理器模板中设置应用设置,以启用 Snapshot Debugger 和 Profiler,请参阅下面的模板代码片段:For an Azure App Service, you can set app settings within the Azure Resource Manager template to enable Snapshot Debugger and Profiler, see the below template snippet:

{
  "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"
      }
    }
  ]
},

后续步骤Next steps

  • 为应用程序生成可触发异常的流量。Generate traffic to your application that can trigger an exception. 然后等待 10 到 15 分钟,这样快照就会发送到 Application Insights 实例。Then, wait 10 to 15 minutes for snapshots to be sent to the Application Insights instance.
  • 请参见 Azure 门户中的快照See snapshots in the Azure portal.
  • 排查 Snapshot Debugger 问题时如需帮助,请参阅 Snapshot Debugger 故障排除For help with troubleshooting Snapshot Debugger issues, see Snapshot Debugger troubleshooting.