使用环境变量配置 Azure Function 的 LogLevel [英] Configure LogLevel of Azure Function using environment variables

查看:36
本文介绍了使用环境变量配置 Azure Function 的 LogLevel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Azure 文档,Functions V2使用 .NET Core 日志记录过滤层次结构用于配置.

As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.

在下面的示例中,ILogger 的一个实例被注入到函数的 Run 方法中.

In the following example, an instance of ILogger is injected into the Run method of the function.

[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
    logger.LogInformation("I don't want to see this in production!"));
}

检查 ILogger 对象时,每个 LoggerInformation 元素的 MinLevel 为 null,这似乎记录了所有级别.

When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.

在生产中,我只想在错误级别登录.我希望能够使用环境变量来配置它,但我找不到任何解释如何实现这一点的文档.我尝试添加以下环境变量无效:

In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:

"logging__logLevel__Default: "Error" 

推荐答案

看代码(12, 3) 对于 azure 函数运行时,这似乎是可能的.您必须将其设置为

Looking at the code (1, 2, 3) for azure functions runtime, this appears to be possible. You have to set it as

export AzureFunctionsJobHost__logging__logLevel__default=Error

这也适用于其他 host.json 设置

This works for other host.json settings too

export AzureFunctionsJobHost__extensions__http__routePrefix=just-another-prefix

这篇关于使用环境变量配置 Azure Function 的 LogLevel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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