重现步骤:
在VS Select HTTP触发器中创建一个新的V2函数应用程序,粘贴以下代码:
log.LogTrace("This is a trace log");
log.LogDebug("This is a debug log");
log.LogInformation("This is an information log");
log.LogWarning("This is a warning log");
log.LogError("This is an error log");
log.LogCritical("This is a critical log");
return new OkResult();转到host.json,配置如下:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": false
},
"fileLoggingMode": "always",
"logLevel": {
"default": "Trace",
"Host.Results": "Error",
"Function": "Trace",
"Host.Aggregator": "Trace"
}
}
}
}运行主机,触发HTTP函数预期结果-跟踪消息应出现在应用程序洞察中
实际结果:应用程序洞察中的查询
union traces
| union exceptions
|union requests
| where timestamp > ago(30d)
| where operation_Id == 'be439155fd015344badd3839da2652a8'
| where customDimensions['InvocationId'] == '6057a32f-0f59-4193-8845-a5f9d972169f'
| order by timestamp asc
| project timestamp, message = iff(message != '', message, iff(innermostMessage != '', innermostMessage, customDimensions.['prop__{OriginalFormat}'])), logLevel = customDimensions.['LogLevel']

timestamp [UTC] message
8/31/2020, 4:00:58.764 PM Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=6057a32f-0f59-4193-8845-a5f9d972169f) Information
8/31/2020, 4:00:58.764 PM Information Logged
8/31/2020, 4:00:58.953 PM error Logged
8/31/2020, 4:00:58.954 PM Warning Logged
8/31/2020, 4:00:58.954 PM Executed 'Function1' (Succeeded, Id=6057a32f-0f59-4193-8845-a5f9d972169f, Duration=190ms) 发布于 2020-09-01 03:22:06
该json文件不正确。fileLoggingMode不是applicationInsights对象的属性。此外,不应在应用程序洞察部分中设置Host.Result和Host.Aggregator类别的日志级别。请参阅reference。
但是,除此之外,您还会遇到问题,因为函数的最小日志类别筛选应该低于或等于应用程序洞察的日志级别。azure函数中的默认日志级别是Information,因此跟踪不会通过。
试试这个:
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Information",
"Host.Results": "Information",
"Function": "Trace",
"Host.Aggregator": "Information"
},
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": false
},
"logLevel": {
"default": "Trace"
}
}
}
}给定上述示例,Function类别的日志级别与应用程序洞察的日志级别相匹配。否则,应用程序洞察日志提供程序将无法拾取日志并将其作为TraceTelemetry发送到应用程序洞察。
https://stackoverflow.com/questions/63674551
复制相似问题