Currently my application is using log4net to log errors, the web.config for this is as followed:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:/paypal/logs/gateway.log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
However, the problem with this is that everyday the logs always go to gateway.log
Does anybody know a way to have a different log file per day using log4net?
Ideally I don't want to have to manually edit the web.config
every night using a scheduled task.
Like using the RollingFileAppender
edit
This is the whole log4net configuration section to roll everyday, the same as @lazyberezovsky answered just adding the log4net and root for clarification
edit2
<file value="c:/paypal/logs/gateway_" />
this will create a file named 'gateway_' and at the end of the day (2012-04-27) it will be renamed as gateway_20120427.log and the next day (2012-04-28) it will create again the file gateway_ and at the end it'll create gateway_20120428.log.PreserveLogFileName
This setting keeps the extension of the file the same after you roll the log.
You should use RollingFileAppender with rollingStyle
Date
and datePatternyyyyMMdd
(this will roll every day).Example of configuration:
UPDATE: I think a better way is to include the date into file name. And use datePattern value only to show when new log file should be created.
In this case all your files will have name like
gateway_20120427.log
.