gpt4 book ai didi

c# - Serilog 相当于 log4net.Config.Watch?

转载 作者:太空狗 更新时间:2023-10-29 23:49:18 25 4
gpt4 key购买 nike

使用 log4net 可以通过更改 app.config 文件在运行时更改日志记录设置。

<add key="log4net.Config.Watch" value="True" />

我的问题很简单:有没有办法为 Serilog 做到这一点?

我已经阅读了有关 LoggingLevelSwitch() 类的内容,但它看起来只能通过代码进行更改。现在当然可以自己对此进行编程,但我正在寻找融入 Serilog 的解决方案。

最佳答案

您不能通过更改 app.config 在运行时更改记录器配置: log4net Documentation

Because the System.Configuration API does not support reloading of the config file the configuration settings cannot be watched using the log4net.Config.XmlConfigurator.ConfigureAndWatch methods. The main advantage of using the System.Configuration APIs to read the configuration data is that it requires less permissions than accessing the configuration file directly.


而且你不能用 Serilog 做到这一点

如您所述,可以在运行时配置日志级别,Source :

var levelSwitch = new LoggingLevelSwitch();

levelSwitch.MinimumLevel = LogEventLevel.Warning;

// configuring the logger using log level switch
var log = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.ColoredConsole()
.CreateLogger();

// and you can switch the log level later on
levelSwitch.MinimumLevel = LogEventLevel.Verbose;

可以看到一些选项here用于更换水槽。

关于c# - Serilog 相当于 log4net.Config.Watch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50715913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com