Log4Net Azure Function 隐藏微软日志

Log4Net Azure Function hide microsoft logs

我在 Azure Functions 中使用 Log4Net 和 .net core 3.1。

我收到多个不必要的信息 Microsoft 日志,如下所示:

Disposing ScriptHost.
Job host stopped
Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function '...'

如何才能只显示错误?

我正在使用这些日志级别为配置了“错误”的系统和 Microsoft 配置 appsettings.json 和 host.json,但我不断收到大量日志。

"logging": {
    "logLevel": {
        "Default": "Debug",
        "System": "Error",
        "Microsoft": "Error",
        "Microsoft.*": "Error"
    }
}

似乎忽略了此配置,在这种情况下我该怎么办?

提前致谢。

此致。

如果您设置 "Microsoft": "Critical" 并通过 logger.LogError 方法在内部记录异常,则不会将其写入日志输出。

"logging": {
    "logLevel": {
        "Default": "Debug",
        "System": "Error",
        "Microsoft": "Critical",
        "Microsoft.*": "Critical"
    }
}

最后我用这个配置修改了 appsettings.json 和 host.json,并且成功了:

"logging": {
    "logLevel": {
        "Default": "Debug",
        "Function.Common.User" : "Debug",
        "Microsoft.*": "Error",
        "Function.*" : "Error",
        "Host.*": "Error"
    }
}