简体   繁体   English

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

[英]ILogger does not log to Application Insights when using Azure Function V2 Durable functions

Can someone, please explain how to force ILogger to actually log something into Application insights when using Azure Function V2 (.net Core)? 请问某人,在使用Azure Function V2(.net Core)时,请解释如何强制ILogger实际将某些内容记录到应用程序洞察中?

We have Application Insights configured and it shows live telementry and unhandled exceptions. 我们已配置Application Insights,它显示实时远程和未处理的异常。 What we are trying to make work is to force Application insights to store logs we create via the default ILogger. 我们正在尝试做的工作是强制应用程序洞察来存储我们通过默认ILogger创建的日志。

No matter what kind of logLevel we are using (Information, Warning, Error, Critical) - nothing gets stored in Application insights. 无论我们使用什么类型的logLevel(信息,警告,错误,严重) - 任何内容都不会存储在应用程序洞察中。

I have also tried creating 500 log messages in the hopes that it might push it to application insights as a batch. 我还尝试创建500条日志消息,希望它可以将其作为批处理推送到应用程序洞察。

Am I missing something obvious here? 我错过了一些明显的东西吗? Can someone suggest how to use the default ILogger so that it passes something to the Application Insights associated with the Azure function App V2 (.net core)? 有人可以建议如何使用默认ILogger,以便它传递给与Azure功能App V2(.net核心)相关联的Application Insights?

host.json 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: 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.");
    }
}

Nothing shows up in Application insights that we logged. 我们记录的应用程序洞察中没有显示任何内容。 But Failures show up as they should: 但失败现象应该出现: 在此输入图像描述

This shows that ILogger saves something on disk: 这表明ILogger在磁盘上保存了一些内容: 在此输入图像描述

More info: 更多信息:

  • Nuget package Microsoft.NET.SDK.Functions v1.0.26 Nuget包Microsoft.NET.SDK.Functions v1.0.26
  • Azure function v2 is connected to the Apllication insights via APPINSIGHTS_INSTRUMENTATIONKEY Azure功能v2通过APPINSIGHTS_INSTRUMENTATIONKEY连接到Apllication洞察
  • Application insights shows live telemetry and Exceptions 应用程序见解显示实时遥测和例外
  • Application insights shows some data, but not from ILogger 应用程序见解显示了一些数据,但不是来自ILogger

The activity log is not the place you want to look for your logs. 活动日志不是您要查找日志的位置。 The logs written using Ilogger are stored as Traces in application insights. 使用Ilogger编写的日志在应用程序洞察中存储为Traces。 You can query them using the Search menu item (the option directly above the Availability menu item in your 2nd screenshot) 您可以使用“ 搜索”菜单项(第二个屏幕截图中“ 可用性”菜单项正上方的选项)查询它们

The activity log will show you events regarding the application insights resource itself, not the data it contains. 活动日志将显示有关应用程序洞察资源本身的事件,而不是它包含的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM