Den*_*sov 3 logging azure azure-application-insights .net-core azure-functions
有人可以解释一下在使用 Azure Function V2 (.net Core) 时如何强制 ILogger 将某些内容实际记录到应用程序洞察中吗?
我们配置了 Application Insights,它显示了实时遥测和未处理的异常。我们试图做的工作是强制应用程序洞察存储我们通过默认 ILogger 创建的日志。
无论我们使用哪种日志级别(信息、警告、错误、关键) - 应用程序洞察中不会存储任何内容。
我还尝试创建 500 条日志消息,希望它可以将其批量推送到应用程序洞察中。
我在这里遗漏了一些明显的东西吗?有人可以建议如何使用默认的 ILogger 以便将某些内容传递给与 Azure 函数应用程序 V2(.net 核心)关联的 Application Insights?
主机文件
{
"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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
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.");
}
}
Run Code Online (Sandbox Code Playgroud)
我们记录的应用程序洞察中没有显示任何内容。但是失败会出现它们应该的样子:

更多信息:
活动日志不是您要查找日志的地方。使用写入的日志Ilogger在应用程序洞察中存储为跟踪。您可以使用“搜索”菜单项(第二个屏幕截图中“可用性”菜单项正上方的选项)查询它们
活动日志将显示有关应用程序洞察资源本身的事件,而不是它包含的数据。
| 归档时间: |
|
| 查看次数: |
3362 次 |
| 最近记录: |