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 op Azure Functions in Windows-serviceabonnementen.

We raden u aan uw toepassing uit te voeren op de Basic-servicelaag of hoger wanneer u Snapshot Debugger gebruikt.

Voor de meeste toepassingen hebben de servicelagen Gratis en Gedeeld onvoldoende geheugen of schijfruimte om momentopnamen op te slaan.

Vereiste

Application Insights-bewaking inschakelen in uw Functions-app

Foutopsporingsprogramma voor momentopnamen inschakelen

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

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

Snapshot Debugger is vooraf geïnstalleerd als onderdeel van de Azure Functions runtime en is standaard uitgeschakeld. Omdat deze is opgenomen in de runtime, hoeft u geen extra NuGet-pakketten of toepassingsinstellingen toe te voegen.

In het eenvoudige voorbeeld van de .NET Core-functie-app dat volgt, .csproj, {Your}Function.csen host.json hebben we Snapshot Debugger 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 waarvoor eindpuntwijzigingen zijn vereist, Azure Government en Microsoft Azure beheerd door 21Vianet.

In het volgende voorbeeld ziet u de host.json die is bijgewerkt met het 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 overschrijvingen van het agenteindpunt voor snapshot debugger:

Eigenschap Cloud voor de Amerikaanse overheid China Cloud
AgentEindpunt https://snapshot.monitor.azure.us https://snapshot.monitor.azure.cn

Foutopsporingsprogramma voor momentopnamen uitschakelen

Als u Snapshot Debugger wilt uitschakelen in uw Functions-app, 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
      }
    }
  }
}

We raden u aan snapshot debugger in te schakelen voor al uw apps om de diagnose van toepassingsuitzondering te vereenvoudigen.

Volgende stappen

  • Genereer verkeer naar uw toepassing dat een uitzondering kan activeren. Wacht vervolgens 10 tot 15 minuten totdat momentopnamen zijn verzonden naar het Application Insights-exemplaar.
  • Bekijk momentopnamen in de Azure Portal.
  • Pas de configuratie van het foutopsporingsprogramma voor momentopnamen aan op basis van uw use-case in uw Functions-app. Zie Configuratie van momentopnamen in host.json voor meer informatie.
  • Zie Problemen met snapshot debugger oplossen voor hulp bij het oplossen van problemen met het foutopsporingsprogramma voor momentopnamen.