请问某人,在使用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.");
}
}
我们记录的应用程序洞察中没有显示任何内容。但失败现象应该出现:
更多信息:
活动日志不是您要查找日志的位置。使用Ilogger
编写的日志在应用程序洞察中存储为Traces。您可以使用“搜索”菜单项(第二个屏幕截图中“可用性”菜单项正上方的选项)查询它们
活动日志将显示有关应用程序洞察资源本身的事件,而不是它包含的数据。