I would like to limit the size of log files to 50MB. I have following configuration in web.config
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Sitecore.Logging"/>
Now sure how to set the maximum file size for logging?
By default Sitecore config comes with log4net.Appender.SitecoreLogFileAppender
type for all the logging. SitecoreLogFileAppender
does not support maximum file size.
You can change this configuration to use log4net.Appender.RollingFileAppender
. It supports maximum file size property.
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="$(dataFolder)/logs/log.{date}.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="0" />
<maximumFileSize value="10MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
</layout>
</appender>
This solution has one drawback - every time file size limit is exceeded, all your logs are removed.
To avoid complete truncation and still solving the problem of too big log files, you can chante setting the maxSizeRollBackups
to a low number, e.g. 2, and reduce the maximumFileSize
respectively. That way, immediately after a truncation, you still have most recent log messages available, rather than none.
Same as for log4net
here: Maximum Filesize of LogFileAppender in Log4Net