简体   繁体   English

在运行时添加/删除 serilog 日志记录级别覆盖

[英]Add/remove serilog logging level overrides at run time

I am using Serilog in.Net 6 WebApi and the required serilog settings, including default logging level and few overrides, are currently being set via appsettings.我在 .Net 6 WebApi 中使用 Serilog 并且所需的 serilog 设置,包括默认日志记录级别和一些覆盖,目前正在通过 appsettings 进行设置。 However, I am looking for a way to dynamically add/remove logging level override for additional namespaces during runtime so that I can capture additional logs on demand for troubleshooting issues, without redeploying the application with setting changes.但是,我正在寻找一种在运行时动态添加/删除附加命名空间的日志记录级别覆盖的方法,以便我可以按需捕获附加日志以解决问题,而无需通过设置更改重新部署应用程序。 Is this possible?这可能吗? Any guidance available on how this can be achieved?关于如何实现这一目标的任何指导?

Thanks!谢谢!

You can implement a custom configuration provider in .NET Core which reads the configuration from Database.您可以在 .NET Core 中实现自定义配置提供程序,它从数据库中读取配置。 And you may need to implement Reload option as well.您可能还需要实施 Reload 选项。 So when you update the database - your configuration will get updated.因此,当您更新数据库时 - 您的配置将得到更新。 Here are some references which may help you.以下是一些可能对您有所帮助的参考资料。

  1. Implement a custom configuration provider in .NET 在 .NET 中实现自定义配置提供程序
  2. A Refreshable SQL Server Configuration Provider for .NET Core 用于 .NET 核心的可刷新 SQL 服务器配置提供程序
  3. Creating a custom ConfigurationProvider for a Entity Framework Core source 为 Entity Framework Core 源代码创建自定义 ConfigurationProvider

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM