首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在azure函数中将loglevel设置为Trace时,无法查看Trace日志

在azure函数中将loglevel设置为Trace时,无法查看Trace日志
EN

Stack Overflow用户
提问于 2020-09-01 00:22:37
回答 1查看 429关注 0票数 0

重现步骤:

在VS Select HTTP触发器中创建一个新的V2函数应用程序,粘贴以下代码:

代码语言:javascript
复制
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,配置如下:

代码语言:javascript
复制
{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": false
      },
      "fileLoggingMode": "always",
      "logLevel": {
        "default": "Trace",
        "Host.Results": "Error",
        "Function": "Trace",
        "Host.Aggregator": "Trace"
      }
    }
  }
}

运行主机,触发HTTP函数预期结果-跟踪消息应出现在应用程序洞察中

实际结果:应用程序洞察中的查询

代码语言:javascript
复制
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']

代码语言:javascript
复制
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)   
EN

回答 1

Stack Overflow用户

发布于 2020-09-01 03:22:06

该json文件不正确。fileLoggingMode不是applicationInsights对象的属性。此外,不应在应用程序洞察部分中设置Host.Result和Host.Aggregator类别的日志级别。请参阅reference

但是,除此之外,您还会遇到问题,因为函数的最小日志类别筛选应该低于或等于应用程序洞察的日志级别。azure函数中的默认日志级别是Information,因此跟踪不会通过。

试试这个:

代码语言:javascript
复制
{
  "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发送到应用程序洞察。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63674551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档