通过 SQL 存储和访问 log4net 配置文件

发布于 2024-09-10 12:35:11 字数 79 浏览 6 评论 0原文

一位同事告诉我,他认为可以在数据库而不是标准配置文件中存储/访问 log4net 的配置文件。如果可以的话,你会怎样做呢?谷歌搜索似乎让我失望。

A co-worker had told me that he thought it was possible to store/access log4net's config file in a database rather than a standard config file. If it's possible, how would you go about doing this? Google search seems to be failing me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻拂→两袖风尘 2024-09-17 12:35:11

您可以将配置 xml 文件存储在数据库行中,并将其作为 XmlElement 提供给 XmlConfigurator.Configure(); 方法。这非常简单,您不会失去 log4net 提供的任何配置功能。需要考虑两件事:

  • 您希望如何处理从数据库读取配置的问题? (故障转移文件中的配置?)
  • 您的应用程序将如何获取配置更改?也许在应用程序重新启动时发生这种情况就足够了,但又可能不会。

You could store the configuration xml file in a database row and feed this as XmlElement to the XmlConfigurator.Configure(); method. This is pretty straight-forward and you do not loose any configuration features that log4net offers. Two things to consider:

  • How do you want to deal with problems reading the config from the database? (fail over configuration in a file?)
  • How would your application pick up configuration changes? Maybe it is good enough that this happens on re-start of the application but then again it may not.
可是我不能没有你 2024-09-17 12:35:11

您可以通过代码本身创建 log4net 配置(请参阅 log4net 配置部分 了解详细信息和简短示例)。拥有可用的设置文件会更方便。

这取决于您需要完成什么。如果您正在寻找相当于数据库中连续的配置文件的东西,那么您可能不走运。

但是,如果您在应用程序中创建了自己的自定义设置表,然后使用这些设置动态创建了记录器,那么您应该已准备就绪。

You can create your log4net configuration through the code itself (see the log4net configuration section for details and a brief example). It is just more convenient to have a settings file available.

It depends on what you need to accomplish. If you're looking for something that is the equivalent of a configuration file sitting in a row in the database, you're probably out of luck.

However, if you created your own custom settings table in your application, and then dynamically created the logger with those settings, you should be all set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文