Using Log4Net I need to write only 2 MB Log file

Kumar AU

Kumar AU

Feb 1 2017 7:23 AM
Dear All,
Kindly let me know in the above code why it’s not writing a log only for 2 MB, (This is my requirement).
My Business Requirement :- Generate a log file every day only one file and keep only 2 MB in size, if the logs are more in size than truncate the old data for the same day.
For My requirement I think below lines of codes are correct, But it’s not working as per my expectation, instead its creating log file which is more in size i.e. 5 MB,6 MB etc..
<appender name="ACLogRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\AgentConnect" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value=".yyyy-MM-dd.lo\g" />
<maxSizeRollBackups value="0" />
<maximumFileSize value="2MB" />
<staticLogFileName value="false" />
<filter type="log4net.Filter.DenyAllFilter" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%message%newline" />

Attachment: code.zip

Answers (2)