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 create开发者_JAVA百科d 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 :)
Could you be missing the type in your file attribute?
<file type="log4net.Util.PatternString" value="%property{LogFilePath}" />
See this for more detail:
http://logging.apache.org/log4net/release/sdk/log4net.Util.PatternString.html
精彩评论