通过 SQL 存储和访问 log4net 配置文件
一位同事告诉我,他认为可以在数据库而不是标准配置文件中存储/访问 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将配置 xml 文件存储在数据库行中,并将其作为
XmlElement
提供给XmlConfigurator.Configure();
方法。这非常简单,您不会失去 log4net 提供的任何配置功能。需要考虑两件事:You could store the configuration xml file in a database row and feed this as
XmlElement
to theXmlConfigurator.Configure();
method. This is pretty straight-forward and you do not loose any configuration features that log4net offers. Two things to consider:您可以通过代码本身创建 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.