How to make rollover when starting the application using Log4net RolloverFileAppender?

Log4Net, configured in our application, uses a name with a date and a file size limit of 10 megabytes.
This automatically causes the new file to tip over at midnight and when it reaches the 10Meg limit. I would also like to flip the record to a new file every time the application is started (or closed).
Can I get all three rolls of behavior?

+5
source share
1 answer

Set appendToFile to false in your configuration file.

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
....
  <appendToFile value="false" />
....
</appender>

EDIT: reply to Craig's comment:

StaticLogFileName CountDirection (. http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.html ), . , , , :

Dim Layout As New PatternLayout("%date{yyyy-MM-dd HH:mm:ss,fff} [%-6thread] %-5level %type{2}.%method(%line) - %message%newline") 
Dim Appender As New log4net.Appender.RollingFileAppender()
Appender.File = Path.Combine(FileSystemHelper.LogDirectory, LogFileName)
Appender.Layout = Layout
Appender.AppendToFile = False ' we will start a new one when the program starts'
Appender.Name = "RollingLogFileAppender"
Appender.Threshold = LogLevel() 'May want to set this by configuration'
Appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size 'This means it will start a new log file each time the log grows to 10Mb'
Appender.MaximumFileSize = "10MB"
Appender.MaxSizeRollBackups = -1 'keep an infinite number of logs'
Appender.StaticLogFileName = True
Appender.CountDirection = 1 ' to reduce rollover costs'
log4net.Config.BasicConfigurator.Configure(Appender)
Appender.ActivateOptions()
+4

All Articles