Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append rolling index BEFORE file extension in log filename

Tags:

log4net

I am using the RollingLogFileAppender and it works great and it's rolling over into new files. But it's adding the .1, .2, etc at the very end of the file. So I end up with .log.1, .log.2, etc. So every file technically has a new extension that explorer doesn't know, so I can't just double click on a file to open.

How can I get the rolling file appender to insert that index BEFORE the file extension?

What I want is

  • .1.log
  • .2.log

Bonus would be for the current file to always be .0.log, that way they always sort correctly in explorer.

EDIT: added my current config settings

<log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <file value="App_Data\\Logs\\" />
      <datePattern value="dd.MM.yyyy'.log'" />
      <staticLogFileName value="false" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="5MB" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>


    <logger name="File">
      <level value="All" />
      <appender-ref ref="RollingLogFileAppender" />
    </logger>
  </log4net>
like image 838
happyfirst Avatar asked Nov 28 '12 15:11

happyfirst


1 Answers

You just need to use the PreserveLogFileNameExtension property on the RollingFileAppender.

See the following questions:

Log4net appender filename issue

Log4net RollingFileAppender Size rollingStyle file extension

like image 65
Milen Kindekov Avatar answered Sep 28 '22 17:09

Milen Kindekov