[英]How to change the Log file path programmatically in log4net?
I am using %property% to set the output file path in the Log4Net configuration file. 我使用%property%来设置Log4Net配置文件中的输出文件路径。 A log file will be created in the APP data folder every time when the application launches. 每次应用程序启动时,都会在APP数据文件夹中创建一个日志文件。 I am using the Composite rolling style for rolling the files. 我正在使用Composite滚动样式来滚动文件。
But now my requirement is to roll/change the file path based on some user interactions in the application . 但现在我的要求是根据应用程序中的一些用户交互来滚动/更改文件路径 。 How can I achieve this, can anyone suggest me to achieve this. 我怎样才能实现这一目标,任何人都可以建议我实现这一目标。
Please let me know if my requirement is not clear. 如果我的要求不明确,请告诉我。
Thanks. 谢谢。
You have 2 questions: 你有两个问题:
code: 码:
LogManager.GetRepository().GetAppenders();
config: 配置:
<appender name="YourAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="~/App_Data/%property{LogName}" />
</appender>
Important is the type="log4net.Util.PatternString"
. 重要的是type="log4net.Util.PatternString"
。 Set the property before initializing log4net. 在初始化log4net之前设置属性。
log4net.GlobalContext.Properties["LogName"] = name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.