NLog 将编程配置的配置对象序列化为 NLog.config 文件
我希望能够使用 XmlLoggingConfiguration 对象从磁盘读取 NLog 配置文件。然后我对该对象进行更改,例如 AddLogLevel(blah)。然后我想将该对象序列化回配置文件中。
除了最后一项之外,我可以实现所有这些目标。我似乎找不到将 XmlLoggingConfiguration 对象序列化回文件的方法。
我想这样做的原因是因为我希望更改永久生效,并且在重置应用程序域时不会重置。
此外,我对配置对象所做的更改不是针对在执行应用程序域中运行的 LogManager,而是针对我将向其发送配置文件的另一个应用程序。
这有道理吗?
如果有人可以帮助我如何让 NLog 序列化 XmlLoggingConfiguration 的实例(如果不可能,请告诉我),请告诉我,谢谢。
PS 我已经检查了主页和维基,但似乎缺少一些信息,因为他们正在参考材料的通信格式之间进行转换。
I want to be able to read an NLog configuration file from disk using the XmlLoggingConfiguration object. I then make changes to that object, e.g. AddLogLevel(blah). I then want to serialize that object back into the configuration file.
I can achieve all of these things with the exception of the last item. I can't seem to find a way of serializing the XmlLoggingConfiguration object back to file.
The reason I want to do this is because I wish the changes to made permanent and not reset when the app domain is reset.
Also, the changes that I make to the configuration object is not for the LogManager that is running in the performing app domain but rather for another application that I will send the configuration file to.
This make sense?
If anyone can help me out with how I get NLog to serialize an instance of XmlLoggingConfiguration (or advise me if it is not possible) then please let me know, thanks.
P.S. I have checked the homepage and wiki but some information seems to be missing as they are making the transition between communication formats for the reference material.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是错误的做法。配置文件可以由框架手动编辑和自动重新加载,这正是我们所需要的。
I decided that this was the wrong approach. The config files can be hand edited and autoreloaded by the framework and that was exactly what we needed.