admin管理员组

文章数量:1123465

I'm trying to setup basic Application Insights logging based on host.json in a 8.0 isolated Azure function project. Below you can find the file I'm using.

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "debugOnly",
    "logLevel": {
      "Host.Aggregator": "Trace",
      "Host.Results": "Trace",
      "Function": "Trace",
      "default": "Trace"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      },
      "enableLiveMetricsFilters": true
    }
  }
}

I'm trying to activate AI logging in the builder code like this :

.ConfigureServices(services =>
{
    services.AddApplicationInsightsTelemetryWorkerService();
    services.ConfigureFunctionsApplicationInsights();
    // You will need extra configuration because above will only log per default Warning (default AI configuration) and above because of following line:
    // .cs#L427
    // This is documented here:
    // 
    // So remove the default logger rule (warning and above). This will result that the default will be Information.
    services.Configure<LoggerFilterOptions>(options =>
    {
        var toRemove = options.Rules.FirstOrDefault(rule => rule.ProviderName
            == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");

        if (toRemove is not null)
        {
            options.Rules.Remove(toRemove);
        }
        //options.MinLevel = LogLevel.Trace;
    });

When I look at the ILogger that is passed along in the azure function class constructor, it has :

  • 2 providers : Microsoft.Azure.Functions.Worker.Logging.WorkerLoggerProvider and {Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider}
  • No FilterOptions.Rules
  • FilterOptions.MinLevel = Information

At least I would expect a MinLevel = Trace ... Am I missing something in my host.json file?

If I add options.MinLevel = LogLevel.Trace to my builder code, I do get MinLevel = Trace. But that's not the purpose, for our UAT & PROD environments we would like to set MinLevel = Information

Been looking around for post with similar approach but couldn't find it.

Regards, Sven

本文标签: Basic Azure function logging isn39t workingStack Overflow