代码之家  ›  专栏  ›  技术社区  ›  Gabriel Ruoff

Azure Function Application Insights日志记录不符合Host.json配置

  •  0
  • Gabriel Ruoff  · 技术社区  · 2 年前

    我已经为一个功能应用程序启用了应用程序洞察,并且正在成功记录跟踪,但当前来自的消息 全部的 日志级别包含在Application insights跟踪表中。我已经这样配置了我的host.json,根据 docs 应记录“Information”及以上的Function,Trace及以上的Host。结果,什么都没有。

    {
     "version": "2.0",
     "logging": {
      "logLevel": {
        "default": "None",
        "Host.Results": "None",
        "Function": "Information",
        "Host.Aggregator": "Trace"
      },
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "excludedTypes": "Dependency;Request;PageView",
          "maxTelemetryItemsPerSecond" : 20,
          "httpAutoCollectionOptions": {
            "enableHttpTriggerExtendedInfoCollection": true,
            "enableW3CDistributedTracing": false,
            "enableResponseHeaderInjection": false
          }
        }
      }
    },
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[3.*, 4.0.0)"
      },
      "functionTimeout": "02:00:00",
       "extensions": {
       "queues": {
                "maxPollingInterval": "00:00:01",
                "visibilityTimeout" : "00:00:15",
                "batchSize": 1,
                "newBatchThreshold": 2,
                "maxDequeueCount": 2
            }
        }
    }
    

    我还使用以下logLevel值进行了测试,该值应防止记录任何跟踪

    "logLevel": {
        "default": "None",
      },
    

    最后,我尝试在应用程序洞察小节以及日志部分中定义logLevel,如建议的那样 here ,但这也没有效果,并且似乎不是根据 host.json reference .

    修改logLevel部分 在本地运行函数时正确更改控制台日志级别,但对Application insights中记录的内容没有影响。如果能在这个问题上得到任何帮助,我将不胜感激。我们目前无法使用应用程序见解,因为记录的数据量太大,这导致我们的成本上升。

    编辑:添加完整的host.json

    0 回复  |  直到 2 年前
        1
  •  0
  •   Suresh Chikkam    2 年前

    我创建了一个功能应用程序,并为其集成了应用程序见解。

    • 然后,我在本地创建了一个Timmer触发器函数应用程序,并通过添加插入键连接到应用程序洞察。

    • 我能够运行功能应用程序并在我的洞察力中跟踪日志,但是,我得到了所有默认的&函数只记录在同一个跟踪表中。因此,为了克服这一点,我已经采取了日志级别,请检查以下文件。

    host.json:

    {
        "version": "2.0",
        "logging": {
          "logLevel": {
            "default": "Information",
            "Host.Results": "Information",
            "Function": "Information",
            "Host.Aggregator": "Trace",
            "Function.Function1.User": "Trace",
            "Function.Function1.System": "Debug"
    
          },
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Dependency;Request;PageView",
            "maxTelemetryItemsPerSecond": 20,
            "httpAutoCollectionOptions": {
              "enableHttpTriggerExtendedInfoCollection": true,
              "enableW3CDistributedTracing": false,
              "enableResponseHeaderInjection": false
            }
          }
        }
      },
      "functionTimeout": "02:00:00",
      "extensions": {
        "queues": {
          "maxPollingInterval": "00:00:01",
          "visibilityTimeout": "00:00:15",
          "batchSize": 1,
          "newBatchThreshold": 2,
          "maxDequeueCount": 2
        }
      }
    }
    
    • 下面是我的样品 功能应用程序 密码
    using System;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Extensions.Logging;
    
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */1 * * * *")] TimerInfo timer, ILogger logger)
        {
    
            logger.LogInformation("This is an information-level log message.");
            logger.LogWarning("This is a warning-level log message.");
            logger.LogError("This is an error-level log message.");
            logger.LogTrace("This is a trace-level log message.");
            logger.LogDebug("This is a debug-level log message.");
            logger.LogCritical("This is a critical-level log message.");
        }
    }
    
    • 通过与host.json文件的通信,我能够成功地运行。

    enter image description here enter image description here

    • 我能够看到按安全级别分隔的功能日志

    查询:

    traces
    | where severityLevel in (0, 1, 2, 3, 4, 5)
    | order by timestamp desc
    

    结果: enter image description here enter image description here enter image description here