Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net rolling daily - Format of filename with date

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.

like image 677
Suresh Avatar asked Aug 04 '15 07:08

Suresh


People also ask

How to allow date time in file name in log4net?

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" />

How does log4net handle rolling log files?

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.

Is there a log file without a date in the name?

… 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.

How to add a date in the generated logging file?

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.


1 Answers

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>
like image 97
Peter Avatar answered Sep 17 '22 18:09

Peter