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

标签 c# .net logging serilog

使用 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/

相关文章:

c# - 如何在两个不同的线程上等待一个任务?

c# - Silverlight 应用程序中的 F# 库?

c# - 无尽的异步和等待?

iPhone:将 NSLog 重定向到文件后,如何将其恢复到控制台?

java - 日志级别的数值有哪些用例?

logging - 限制 docker 日志记录

c# - (Excel 互操作)如何将一个工作表复制到 VSTO 中的另一个工作簿?

c# - 方法订阅与 lambda 委托(delegate)订阅 - 哪个以及为什么?

c# - .Net 4 MemoryCache 泄漏并发垃圾收集

c# - 不能在FB post发图片,这个status update好像是空白。请写一些东西或附上链接或照片以更新您的状态