C#log4net的 - 动态更改日志目录编程 [英] C# Log4Net - dynamically change log directory programmatically
问题描述
我完成大部分关于编程方式更改日志目录中的相关主题阅读,但答案都有些先进的。
I read through most of the related topics regarding changing log directory programmatically, but the answers were a little advanced.
我的问题是试图动态地改变在我的日志文件是从我的C#应用程序保存。我有一个浏览按钮文本框来选择它应该被保存。
My problem is trying to dynamically change where my log file is saved from my C# application. I have a text box with a browse button to choose where it should be saved.
任何人有一个想法或可以点我在一些代码正确的方向?我试着玩弄类似的想法,但似乎无法得到它的权利。
Anyone have an idea or can point me in the right direction with some code? I've tried playing around with similar ideas but can't seem to get it right.
感谢您的帮助。
杰夫
推荐答案
如果你希望你的日志文件是在一个指定的位置,将在运行决定的地方时间可能是你的项目输出目录,那么你可以配置这样的config文件条目
If you want your log file to be place at a specified location which will be decided at run time may be your project output directory then you can configure your .config file entry in that way
file type="log4net.Util.PatternString" value="%property{LogFileName}.txt"
,然后在代码中调用之前log4net的配置,设置如下
and then in the code before calling log4net configure, set the new path like below
log4net.GlobalContext.Properties["LogFileName"] = @"E:\file1"; //log file path
log4net.Config.XmlConfigurator.Configure();
所以,如果你的要求改变日志目录如此频繁然后更新属性值,然后按<每次code> .Configure()以及
这篇关于C#log4net的 - 动态更改日志目录编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!