使用Azure Function V2 Durable函数时,ILogger不会登录到Application Insights

问题描述 投票:0回答:1

请问某人,在使用Azure Function V2(.net Core)时,请解释如何强制ILogger实际将某些内容记录到应用程序洞察中?

我们已配置Application Insights,它显示实时远程和未处理的异常。我们正在尝试做的工作是强制应用程序洞察来存储我们通过默认ILogger创建的日志。

无论我们使用什么类型的logLevel(信息,警告,错误,严重) - 任何内容都不会存储在应用程序洞察中。

我还尝试创建500条日志消息,希望它可以将其作为批处理推送到应用程序洞察。

我错过了一些明显的东西吗?有人可以建议如何使用默认ILogger,以便它传递给与Azure功能App V2(.net核心)相关联的Application Insights?

host.json

{
  "version": "2.0",
  "functionTimeout": "00:10:00",
  "extensions": {
    "durableTask": {
      "maxConcurrentActivityFunctions": 4,
      "maxConcurrentOrchestratorFunctions": 1
    }
  },
  "logging": {
    "fileLoggingMode": "debugOnly",
    "logLevel": {
      "default": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 5
      }
    }
  }
}

Azure Function V2,TimerTrigger,DurableOrchestrationClient:

[FunctionName("MainTriggerEntry")]
public static async Task RunMainTriggerEntry([TimerTrigger("%CRON_EXPRESSION%", RunOnStartup = false)]TimerInfo timer,
[OrchestrationClient]DurableOrchestrationClient starter, ILogger log)
{
    log.LogInformation("[Information] Message!");
    log.LogError("[Error]. Something occured");
    log.LogCritical("[Critical] Critical issue");
    for (var i = 0; i < 500; i++)
    {
        log.LogWarning($"[Warning] Logging to Application insights. {i}");
    }

    // We don't want more than one orchestrator running at the same time:
    var orchestrationStatus = await starter.GetStatusAsync(OrchestratorInstanceGuid);
    if (orchestrationStatus == null || !orchestrationStatus.IsBusy())
    {
        var instanceId = await starter.StartNewAsync(OrchestratorFunctionName, OrchestratorInstanceGuid, null);
        log.LogInformation($"Triggering {OrchestratorFunctionName} function with an ID '{instanceId}'.");
    }
    else
    {
        log.LogInformation($"{OrchestratorFunctionName} function with an ID '{OrchestratorInstanceGuid}' is already running.");
    }
}

我们记录的应用程序洞察中没有显示任何内容。但失败现象应该出现:enter image description here

这表明ILogger在磁盘上保存了一些东西:enter image description here

更多信息:

  • Nuget包Microsoft.NET.SDK.Functions v1.0.26
  • Azure功能v2通过APPINSIGHTS_INSTRUMENTATIONKEY连接到Apllication洞察
  • 应用程序见解显示实时遥测和例外
  • 应用程序见解显示了一些数据,但不是来自ILogger
azure logging .net-core azure-functions azure-application-insights
1个回答
3
投票

活动日志不是您要查找日志的位置。使用Ilogger编写的日志在应用程序洞察中存储为Traces。您可以使用“搜索”菜单项(第二个屏幕截图中“可用性”菜单项正上方的选项)查询它们

活动日志将显示有关应用程序洞察资源本身的事件,而不是它包含的数据。

© www.soinside.com 2019 - 2024. All rights reserved.