I have an appender setup like this
<appender name="Scheduler_Appender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp\ApplicationLog.txt"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd"/>
<appendToFile value="true"/>
<staticLogFileName value="true"/>
<layout type="MinLayout">
<locationInfo value="true"/>
</layout>
</appender>
When the log file first gets created the file name is simply ApplicationLog.txt this is correct.
However when the logging rolls - the filename that gets generated is ApplicationLog.txt20100323 (for example), and not ApplicationLog20100323.txt
How can I change the configuration so files are rolled to [FileName][Date].[ext] rather than [FileName].[ext][Date]
Thanks
Update
I tried this, just some experiment, but now its generating files with a .pxp extension for some reason...
<appender name="Scheduler_Appender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp\Scheduler"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd.txt"/>
<appendToFile value="true"/>
<staticLogFileName valu开发者_运维百科e="false"/>
<layout type="MinLayout">
</layout>
</appender>
I believe the setting you want is PreserveLogFileNameExtension
:
<appender name="Scheduler_Appender" type="log4net.Appender.RollingFileAppender">
...
<PreserveLogFileNameExtension value="true" />
Note: this property is not available in the currently released binary (version 1.2.10.0) so you would have to grab the latest source and go from there.
<appender name="cheduler_Appender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp\Scheduler"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd'.txt'"/>
<appendToFile value="true"/>
<staticLogFileName value="false"/>
<layout type="MinLayout">
</layout>
</appender>
Try this one, it will create log file based on current date
log filename (change the format accordingly) : "log-[15-02-2017].[15.57.10].log"
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<appendToFile value="true" />
<rollingStyle value="Date" />
<file type="log4net.Util.PatternString">
<conversionPattern value="log-[%date{dd-MM-yyyy}].[%date{HH.mm.ss}].log" />
</file>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p [%logger:%L] - %m%n" />
</layout>
</appender>
精彩评论