停止 Azure 函数记录“正在执行"和“已执行"消息 [英] Stop an Azure Function from logging the “Executing” and “Executed” messages

查看:17
本文介绍了停止 Azure 函数记录“正在执行"和“已执行"消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 Azure 函数被触发时,它会记录正在执行"和已执行"消息.这在测试过程中很好,但由于这个函数被触发了很多,它会创建很多不需要的日志消息.我自己添加的日志记录对我很重要,但我想禁用函数自己的正在执行"和已执行"消息.澄清一下,我不想记录以下消息:

When my Azure Function is triggered, it logs "Executing" and "Executed" messages. This is fine during testing but as this Function gets triggered a lot, it is creating a lot of unwanted log messages. The logging that I have added myself is important to me but I would like to disable the Function's own "Executing" and "Executed" messages. To clarify, it is the following messages I don’t want logged:

Executing ‘MyFunctionName’ (Reason='New ServiceBus message detected……etc’)

Executed ‘MyFunctionName’ (Succeeded, Id=a99c6932-788f-439e-a7db-aad7f607d5ea)

推荐答案

你要去掉的执行日志是函数运行时产生的,我们可以设置更高的日志级别来过滤信息,保留我们自定义的信息.

The execution logs you want to get rid of is generated by function runtime, we can set a higher log level to filter information and keep our self-defined info.

转到 Azure 门户,平台功能> 函数应用设置> host.json

Go to Azure portal, Platform features> Function app settings> host.json

对于函数应用 v2,此设置位于 host.json,排除的日志无处可寻.

For Function app v2, with this setting in host.json, the logs excluded are nowhere to find.

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "Function.MyFunctionName.User": "Information",
      "Function": "Error"
    }
  }
}

对于 v1,使用 ILogger 而不是 TraceWriter.host.json 仅限制发送到 Application Insights 的内容,这意味着我们仍然可以在控制台或文件日志中看到它们.

For v1, use ILogger instead of TraceWriter. This setting in host.json only restricts those sent to Application Insights, which means we can still see them in console or file logs.

{
  "logger": {
    "categoryFilter": {
      "categoryLevels": {
        "Host.Executor": "Error"
      }
    }
  }
}

这篇关于停止 Azure 函数记录“正在执行"和“已执行"消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆