Reputation: 129
I am trying to create file with naming convention as Service_HH_mm_ss.txt
.
file naming format is
<file type="log4net.Util.PatternString" value="C:\\Log\\%date{yyyy-MM-dd}\\Service_%date{HH_mm_ss}.log" />
Also i have given file max size to
<rollingStyle value="Size" />
<maximumFileSize value="10KB" />
i want to create new file if and only if size exceed to 10KB, but new file is getting creating on each and every second.
not able to find the solution.
Config file code is:
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\\Log\\%date{yyyy-MM-dd}\\Service_%date{HH_mm_ss}.log" />
<encoding value="utf-8" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="20" />
<maximumFileSize value="10KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level - %message%n" />
</layout>
Is it possible to do what i want, i ma not getting any solution.
Upvotes: 0
Views: 276
Reputation: 59
In your Appender definition the value for the File name changes every second. Therefor log4net creates a new file every second. If you need the exact time to be part of the file name, you can use rolling Style 'Composite' and add a DatePattern like so:
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\\Log\\%date{yyyy-MM-dd}\\Service_" />
<encoding value="utf-8" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value = "HH_mm_ss'.log'"
<maxSizeRollBackups value="20" />
<maximumFileSize value="10KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level - %message%n" />
</layout>
Upvotes: 2