I want My log file something like this date.filename.txt. which rolls out new file everyday.
i am able to generate file in this format filename.date.txt. By using the below configuration
<appender name="SLSILogFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" >
<converter>
<name value="logfilename" />
<type
value="FilenamePatternConverter" />
</converter>
<conversionPattern
value="%property{TestURL}%logfilename{LocalApplicationData}" />
</file>
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<datePattern value="'.'yyyy.MM.dd'.log'" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>
I've tried a lot of things but nothing helps.
Using Log4Net 1.2.13 we use the following configuration settings to allow date time in the file name. <file type="log4net.Util.PatternString" value="E:/logname-%utcdate {yyyy-MM-dd}.txt" />
On startup, log4net would generate the first filename in the rolling sequence. It would detect that that file already exist and would then decide to roll to the second file, but when that one also already exists, it does not decide to roll but instead clears it and overwrites everything in that second log file.
… Each log file is rolled out every day, and the file without date in its name is the current log file. Suppose today is 2012-11-04, and at midnight, log4j will back up the app.log file into app.log.2012-11-04, and the app.log file become logging for the new day, 2012-11-05, and so on.
Today we will see how to customize the logging file behavior and will see how to add a date in the file. Above “<datePattern../>” tag allows you to use date pattern in the generated logging file. This is another step that requires to be done to make date-based log file generation work.
You can add the filename in the datePattern like:
<appender name="SLSILogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp\logs\" />
<datePattern value="dd.MM.yyyy'.filename.log'" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With