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

查看:92
本文介绍了使用环境变量配置Azure功能的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" 

推荐答案

查看代码(

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设置

export AzureFunctionsJobHost__extensions__http__routePrefix=just-another-prefix

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

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