公告
财富商城
积分规则
提问
发文
2019-01-04 19:03发布
做个烂人
I would like to have files named for example:
dd.mm.yyyy.log
How is this possible with log4net?
Using Log4Net 1.2.13 we use the following configuration settings to allow date time in the file name.
<file type="log4net.Util.PatternString" value="E:/logname-%utcdate{yyyy-MM-dd}.txt" />
Which will provide files in the following convention: logname-2015-04-17.txt
logname-2015-04-17.txt
With this it's usually best to have the following to ensure you're holding 1 log per day.
<rollingStyle value="Date" /> <datePattern value="yyyyMMdd" />
If size of file is a concern the following allows 500 files of 5MB in size until a new day spawns. CountDirection allows Ascending or Descending numbering of files which are no longer current.
<maxSizeRollBackups value="500" /> <maximumFileSize value="5MB" /> <rollingStyle value="Composite" /> <datePattern value="yyyyMMdd" /> <CountDirection value="1"/> <staticLogFileName value="true" />
To preserve file extension:
<log4net> <root> <level value="DEBUG"/> <appender-ref ref="RollingLogFileAppender"/> </root> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="D:\\LogFolder\\%date{yyyyMM}\\SchT.log" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <maximumFileSize value="30MB" /> <staticLogFileName value="true" /> <preserveLogFileNameExtension value="true"/> <datePattern value="ddMMyyyy" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> </appender> </log4net>
最多设置5个标签!
Using Log4Net 1.2.13 we use the following configuration settings to allow date time in the file name.
<file type="log4net.Util.PatternString" value="E:/logname-%utcdate{yyyy-MM-dd}.txt" />
Which will provide files in the following convention:
logname-2015-04-17.txt
With this it's usually best to have the following to ensure you're holding 1 log per day.
If size of file is a concern the following allows 500 files of 5MB in size until a new day spawns. CountDirection allows Ascending or Descending numbering of files which are no longer current.
To preserve file extension: