每天创建一个文件夹,达到最大大小时创建一个新文件
Create a folder for each day and a new file when max size is reached
我需要在我的应用程序位置之外创建一个日志目录,并为每个日期创建一个文件夹。我还需要在达到最大大小时创建一个新文件。
我正在使用此代码:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="D:/Logs/EmailService/"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<datePattern value=".yyyyMMdd\\'service.log"/>
<staticLogFileName value="true"/>
<maximumFileSize value="5MB"/>
<maxSizeRollBackups value="20"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] – %message%newline"/>
</layout>
<lockingModel type="log4net.Appender.FileAppender+MutexLock" />
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
但是,没有创建文件。有什么问题吗?
更新
这是完整的代码,连同@stuartd 的回答能够按日期创建目录:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="D:/Logs/emailservice/%date{yyyyMMdd}/logfile.log"/>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<maximumFileSize value="5MB"/>
<maxSizeRollBackups value="20"/>
<datePattern value="yyyyMMdd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] – %message%newline"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="WARN" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
为了滚动日期和大小,您必须在配置中设置 <rollingStyle value="Composite"/>
- from the docs:
RollingMode.Composite - Roll files based on both the size and date of the file
我需要在我的应用程序位置之外创建一个日志目录,并为每个日期创建一个文件夹。我还需要在达到最大大小时创建一个新文件。
我正在使用此代码:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="D:/Logs/EmailService/"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<datePattern value=".yyyyMMdd\\'service.log"/>
<staticLogFileName value="true"/>
<maximumFileSize value="5MB"/>
<maxSizeRollBackups value="20"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] – %message%newline"/>
</layout>
<lockingModel type="log4net.Appender.FileAppender+MutexLock" />
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
但是,没有创建文件。有什么问题吗?
更新
这是完整的代码,连同@stuartd 的回答能够按日期创建目录:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="D:/Logs/emailservice/%date{yyyyMMdd}/logfile.log"/>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<maximumFileSize value="5MB"/>
<maxSizeRollBackups value="20"/>
<datePattern value="yyyyMMdd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] – %message%newline"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="WARN" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
为了滚动日期和大小,您必须在配置中设置 <rollingStyle value="Composite"/>
- from the docs:
RollingMode.Composite - Roll files based on both the size and date of the file