log4net动态配置
我有一个 VB 控制台应用程序,我正在尝试动态命名 FileAppender 的 log4net 输出文件。
正在创建日志文件并且它具有正确的内容,问题是正在使用名称“%property{LogFilePath}”创建该文件。换句话说,它根本不进行字符串替换。
在 app.config 中:
<log4net>
<appender name="myAppender" type="log4net.Appender.FileAppender">
<file value="%property{LogFilePath}" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="myAppender" />
</root>
</log4net>
在我的 VB 文件中:
Private _logger As ILog
Private Sub InitializeLogger()
log4net.GlobalContext.Properties("LogFilePath") = "C:\Logs\myLog.log"
XmlConfigurator.Configure()
_logger = LogManager.GetLogger("myAppender")
End Sub
回顾一下,正在创建日志文件并且它确实具有预期的内容,唯一的问题是日志文件名保留为“%property{LogFilePath}”而不是被替换通过“C:\Logs\myLog.log”
任何帮助将不胜感激:)
I have a VB console app and I am trying to dynamically name the log4net output file of my FileAppender.
The log file is being created and it has the proper contents, the problem is that the file is being created with the name "%property{LogFilePath}". In other words, it is not doing the string replace at all.
In app.config:
<log4net>
<appender name="myAppender" type="log4net.Appender.FileAppender">
<file value="%property{LogFilePath}" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="myAppender" />
</root>
</log4net>
In my VB File:
Private _logger As ILog
Private Sub InitializeLogger()
log4net.GlobalContext.Properties("LogFilePath") = "C:\Logs\myLog.log"
XmlConfigurator.Configure()
_logger = LogManager.GetLogger("myAppender")
End Sub
To recap, the log file IS being created and it does have the expected content, the only problem is that the log file name is remaining as "%property{LogFilePath}" instead of being replaced by "C:\Logs\myLog.log"
Any help would be greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的文件属性中是否缺少类型?
有关更多详细信息,请参阅此:
http://logging.apache.org/log4net/release/sdk /log4net.Util.PatternString.html
Could you be missing the type in your file attribute?
See this for more detail:
http://logging.apache.org/log4net/release/sdk/log4net.Util.PatternString.html