Delen via


Snapshot Debugger inschakelen voor .NET- en .NET Core-apps in Azure Functions

Snapshot Debugger werkt momenteel voor ASP.NET en ASP.NET Core-apps die worden uitgevoerd in Azure Functions in Windows-serviceplannen.

U wordt aangeraden uw toepassing uit te voeren op de Basic- of hogere servicelagen wanneer u snapshot debugger gebruikt. Voor de meeste toepassingen:

  • De servicelagen Gratis en Gedeeld hebben onvoldoende geheugen of schijfruimte om momentopnamen te besparen.
  • De verbruikslaag is momenteel niet beschikbaar voor het foutopsporingsprogramma voor momentopnamen.

Snapshot Debugger is vooraf geïnstalleerd als onderdeel van de Azure Functions-runtime, dus u hoeft geen extra NuGet-pakketten of toepassingsinstellingen toe te voegen.

Vereiste

Application Insights-bewaking inschakelen in uw Functions-app.

Snapshot Debugger inschakelen

Als u Snapshot Debugger in uw Functions-app wilt inschakelen, voegt u de snapshotConfiguration eigenschap toe aan uw host.json-bestand en implementeert u de functie opnieuw. Voorbeeld:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "snapshotConfiguration": {
        "isEnabled": true
      }
    }
  }
}

Genereer verkeer naar uw toepassing waarmee een uitzondering kan worden geactiveerd. Wacht vervolgens 10 tot 15 minuten totdat momentopnamen naar het Application Insights-exemplaar zijn verzonden.

U kunt controleren of Snapshot Debugger is ingeschakeld door uw .NET-functie-app-bestanden te controleren. In de volgende eenvoudige .NET-functie-app worden bijvoorbeeld de .csproj, {Your}Function.csen host.json van uw .NET-toepassing momentopnamenopsporingsprogramma weergegeven als ingeschakeld:

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.31" />
</ItemGroup>
<ItemGroup>
    <None Update="host.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
</ItemGroup>
</Project>

{Your}Function.cs

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace SnapshotCollectorAzureFunction
{
    public static class ExceptionFunction
    {
        [FunctionName("ExceptionFunction")]
        public static Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            throw new NotImplementedException("Dummy");
        }
    }
}

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      },
      "snapshotConfiguration": {
        "isEnabled": true
      }
    }
  }
}

Snapshot Debugger inschakelen voor andere clouds

Momenteel zijn de enige regio's die eindpuntwijzigingen vereisen Azure Government en Microsoft Azure beheerd door 21Vianet.

In het volgende voorbeeld ziet u het host.json bijgewerkte eindpunt van de Cloud-agent voor de Amerikaanse overheid:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      },
      "snapshotConfiguration": {
        "isEnabled": true,
        "agentEndpoint": "https://snapshot.monitor.azure.us"
      }
    }
  }
}

Dit zijn de ondersteunde onderdrukkingen van het eindpunt van de Snapshot Debugger-agent:

Eigenschappen Cloud voor de Amerikaanse overheid China-cloud
agentEndpoint https://snapshot.monitor.azure.us https://snapshot.monitor.azure.cn

Snapshot Debugger uitschakelen

Als u Snapshot Debugger in uw Functions-app wilt uitschakelen, werkt u het host.json-bestand bij door de snapshotConfiguration.isEnabled eigenschap in te stellen op false.

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "snapshotConfiguration": {
        "isEnabled": false
      }
    }
  }
}

Volgende stappen