Log4net
  1. Log4net
  2. LOG4NET-64

[PATCH] to RollingFileAppender.cs to add the ability to preserve the log file name extension when rolling the log file.

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.9
    • Fix Version/s: 1.2.11
    • Component/s: Appenders
    • Labels:
      None

      Description

      Normally, when the log file is rolled the file name extension is not preserved.

      For example, file.log is rolled to file.log.1 or file.log.yyyy-MM-dd.

      However, this may not be desired in all cases and it may be necessary to preserve the log file name extension when the log file is rolled. Most notably, this feature is useful for maintaining file associations under Windows so that all log files can be associated with a particaular text viewer.

      For example, file.log is rolled to file.1.log or file.yyyy-MM-dd.log.

      This patch adds an additional boolean property PreserveLogFileNameExtension to the RollingFileAppender class which is used to toggle this behavior.

      1. log4net-64.patch
        0.9 kB
        Eike-Peter Falk
      2. LOG4NET-64.patch
        11 kB
        Ron Grabowski
      3. LOG4NET-64.patch
        5 kB
        Ayende Rahien
      4. patch.txt
        5 kB
        Joshua Bassett

        Issue Links

          Activity

          Hide
          Petr Vones added a comment - - edited

          It does not work for Date or Composite RollingStyle in 1.2.11.0 release version. It still apeends the datePattern at the end of filename. The only configuration when it works is Size RollingStyle. The configuration is:

          <log4net>
          <appender name="File" type="log4net.Appender.RollingFileAppender">
          <file value="Application.log"/>
          <appendToFile value="true"/>
          <rollingStyle value="Composite"/>
          <maxSizeRollBackups value="-1"/>
          <maximumFileSize value="100KB"/>
          <datePattern value="yyyyMMdd"/>
          <preserveLogFileNameExtension value="true"/>
          <filter type="log4net.Filter.LevelRangeFilter">
          <acceptOnMatch value="true"/>
          <levelMin value="DEBUG"/>
          <levelMax value="FATAL"/>
          </filter>
          <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date %-5level [%property] %logger - %message%newline"/>
          </layout>
          </appender>
          <root>
          <level value="ALL"/>
          <appender-ref ref="File"/>
          </root>
          </log4net>

          And the output is:
          Application.1.log
          Application.1.log20120406
          Application.log
          Application.log20120406

          Show
          Petr Vones added a comment - - edited It does not work for Date or Composite RollingStyle in 1.2.11.0 release version. It still apeends the datePattern at the end of filename. The only configuration when it works is Size RollingStyle. The configuration is: <log4net> <appender name="File" type="log4net.Appender.RollingFileAppender"> <file value="Application.log"/> <appendToFile value="true"/> <rollingStyle value="Composite"/> <maxSizeRollBackups value="-1"/> <maximumFileSize value="100KB"/> <datePattern value="yyyyMMdd"/> <preserveLogFileNameExtension value="true"/> <filter type="log4net.Filter.LevelRangeFilter"> <acceptOnMatch value="true"/> <levelMin value="DEBUG"/> <levelMax value="FATAL"/> </filter> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date %-5level [%property] %logger - %message%newline"/> </layout> </appender> <root> <level value="ALL"/> <appender-ref ref="File"/> </root> </log4net> And the output is: Application.1.log Application.1.log20120406 Application.log Application.log20120406
          Hide
          Eike-Peter Falk added a comment -

          This patch should fix this issue.

          Show
          Eike-Peter Falk added a comment - This patch should fix this issue.
          Hide
          Hakan Lindestaf added a comment - - edited

          I have a problem with this issue, some of the files are still named in the old format.
          Here's what my directory output looks like:
          Volume in drive C has no label.
          Volume Serial Number is 7057-2FE1

          Directory of C:\inetpub\wwwroot\KickService\Logs

          11/09/2009 08:32 AM <DIR> .
          11/09/2009 08:32 AM <DIR> ..
          11/09/2009 07:56 AM 12,822 Service.log
          10/28/2009 11:27 PM 748,549 Service.log20091028
          10/29/2009 10:30 PM 738,261 Service.log20091029
          11/05/2009 10:42 PM 819,465 Service.log20091105
          11/06/2009 11:20 PM 873,142 Service.log20091106
          11/07/2009 02:42 PM 148,499 Service.log20091107
          11/08/2009 09:06 PM 81,809 Service.log20091108
          10/16/2009 10:51 PM 586,003 Service20091016.log
          10/20/2009 10:51 PM 654,559 Service20091020.log
          10/21/2009 10:46 PM 848,594 Service20091021.log
          10/22/2009 10:57 PM 6,586,212 Service20091022.log
          10/25/2009 11:51 PM 264,567 Service20091025.log
          10/26/2009 11:54 PM 908,770 Service20091026.log
          10/27/2009 11:53 PM 426,759 Service20091027.log
          10/30/2009 11:54 PM 456,209 Service20091030.log
          10/31/2009 11:54 PM 26,600 Service20091031.log
          11/01/2009 11:54 PM 153,698 Service20091101.log
          11/02/2009 11:48 PM 1,194,835 Service20091102.log
          11/03/2009 11:59 PM 2,587,370 Service20091103.log
          11/04/2009 11:56 PM 846,138 Service20091104.log
          11/09/2009 08:32 AM 0 x.x
          21 File(s) 18,962,861 bytes
          2 Dir(s) 32,061,755,392 bytes free

          See how there is a mix of the output formats. I haven't had a chance to look thru the code yet. I'm running log4net from svn trunk. Here's my config:
          <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="C:\Inetpub\wwwroot\Service\Logs\Service.log"/>
          <appendToFile value="true"/>
          <maxSizeRollBackups value="30"/>
          <rollingStyle value="Date"/>
          <staticLogFileName value="true"/>
          <datePattern value="yyyyMMdd"/>
          <preserveLogFileNameExtension value="true"/>
          <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%property

          {SessionId}

          ] %-5level %logger [%property

          {NDC}

          ] - %message%newline"/>
          </layout>
          </appender>

          Show
          Hakan Lindestaf added a comment - - edited I have a problem with this issue, some of the files are still named in the old format. Here's what my directory output looks like: Volume in drive C has no label. Volume Serial Number is 7057-2FE1 Directory of C:\inetpub\wwwroot\KickService\Logs 11/09/2009 08:32 AM <DIR> . 11/09/2009 08:32 AM <DIR> .. 11/09/2009 07:56 AM 12,822 Service.log 10/28/2009 11:27 PM 748,549 Service.log20091028 10/29/2009 10:30 PM 738,261 Service.log20091029 11/05/2009 10:42 PM 819,465 Service.log20091105 11/06/2009 11:20 PM 873,142 Service.log20091106 11/07/2009 02:42 PM 148,499 Service.log20091107 11/08/2009 09:06 PM 81,809 Service.log20091108 10/16/2009 10:51 PM 586,003 Service20091016.log 10/20/2009 10:51 PM 654,559 Service20091020.log 10/21/2009 10:46 PM 848,594 Service20091021.log 10/22/2009 10:57 PM 6,586,212 Service20091022.log 10/25/2009 11:51 PM 264,567 Service20091025.log 10/26/2009 11:54 PM 908,770 Service20091026.log 10/27/2009 11:53 PM 426,759 Service20091027.log 10/30/2009 11:54 PM 456,209 Service20091030.log 10/31/2009 11:54 PM 26,600 Service20091031.log 11/01/2009 11:54 PM 153,698 Service20091101.log 11/02/2009 11:48 PM 1,194,835 Service20091102.log 11/03/2009 11:59 PM 2,587,370 Service20091103.log 11/04/2009 11:56 PM 846,138 Service20091104.log 11/09/2009 08:32 AM 0 x.x 21 File(s) 18,962,861 bytes 2 Dir(s) 32,061,755,392 bytes free See how there is a mix of the output formats. I haven't had a chance to look thru the code yet. I'm running log4net from svn trunk. Here's my config: <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="C:\Inetpub\wwwroot\Service\Logs\Service.log"/> <appendToFile value="true"/> <maxSizeRollBackups value="30"/> <rollingStyle value="Date"/> <staticLogFileName value="true"/> <datePattern value="yyyyMMdd"/> <preserveLogFileNameExtension value="true"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%property {SessionId} ] %-5level %logger [%property {NDC} ] - %message%newline"/> </layout> </appender>
          Hide
          Ron Grabowski added a comment -

          Fixed. Thanks Joshua and Ayende.

          Show
          Ron Grabowski added a comment - Fixed. Thanks Joshua and Ayende.
          Hide
          Ron Grabowski added a comment - - edited

          My uploaded patch also fixes the issue when the filename is absolute like "c:
          log.txt". The first two patches would write to the file correctly but would incorrectly place the rolled files in the \bin directory of the running program.

          Show
          Ron Grabowski added a comment - - edited My uploaded patch also fixes the issue when the filename is absolute like "c: log.txt". The first two patches would write to the file correctly but would incorrectly place the rolled files in the \bin directory of the running program.
          Hide
          Ron Grabowski added a comment -

          Based on the two earlier patches for this ticket.

          This patch enables the last log file to be recognized. If a directory already has these files:

          log.1.txt
          log.2.txt

          log4net will recognize that logging should resume with log.3.txt. The original RollingFileAppender had supported this but the first two patches broke that functionality.

          This patch also enables the rolling date option and the composite option to correctly preserve the file extension:

          log.2008-10-12.1.txt
          log.2008-10-12.2.txt
          log.2008-10-12.3.txt
          log.2008-10-13.1.txt
          log.2008-10-13.2.txt
          log.2008-10-13.3.txt

          Show
          Ron Grabowski added a comment - Based on the two earlier patches for this ticket. This patch enables the last log file to be recognized. If a directory already has these files: log.1.txt log.2.txt log4net will recognize that logging should resume with log.3.txt. The original RollingFileAppender had supported this but the first two patches broke that functionality. This patch also enables the rolling date option and the composite option to correctly preserve the file extension: log.2008-10-12.1.txt log.2008-10-12.2.txt log.2008-10-12.3.txt log.2008-10-13.1.txt log.2008-10-13.2.txt log.2008-10-13.3.txt
          Hide
          Ayende Rahien added a comment -

          Updated patch

          Show
          Ayende Rahien added a comment - Updated patch
          Hide
          Ron Grabowski added a comment -

          TSVN won't let me apply the patch. You can help out by re-submiting the patch along with some test cases.

          Show
          Ron Grabowski added a comment - TSVN won't let me apply the patch. You can help out by re-submiting the patch along with some test cases.
          Hide
          Edouard Mercier added a comment -

          The suggested feature, which consists in preserving the file extension, is also a must for me. I am ready to provide the patch if you need to. Does anyone knows why this is currently blocked? Thank you.

          Regards,
          Edouard

          Show
          Edouard Mercier added a comment - The suggested feature, which consists in preserving the file extension, is also a must for me. I am ready to provide the patch if you need to. Does anyone knows why this is currently blocked? Thank you. Regards, Edouard
          Hide
          Nicko Cadell added a comment -

          This is an enhancment and reworking of the patch submitted as part of LOG4NET-64

          Show
          Nicko Cadell added a comment - This is an enhancment and reworking of the patch submitted as part of LOG4NET-64
          Hide
          Ron Grabowski added a comment -

          I wasn't able to apply this patch with TSVN (TortoiseSVN 1.3.2, Build 5840). TSVN requires the header to be in this format:

          Index: RollingFileAppender.cs
          ===================================================================
          — RollingFileAppender.cs (revision 381326)
          +++ RollingFileAppender.cs (working copy)

          After downloading the file (with FireFox, IE6, and wget) and correcting the header, I get the following error:

          "An unknown line type was found in line 5 !"

          This is line 5:

          set

          { m_staticLogFileName = value; }

          Maybe Joshua could .zip the patch?

          Show
          Ron Grabowski added a comment - I wasn't able to apply this patch with TSVN (TortoiseSVN 1.3.2, Build 5840). TSVN requires the header to be in this format: Index: RollingFileAppender.cs =================================================================== — RollingFileAppender.cs (revision 381326) +++ RollingFileAppender.cs (working copy) After downloading the file (with FireFox, IE6, and wget) and correcting the header, I get the following error: "An unknown line type was found in line 5 !" This is line 5: set { m_staticLogFileName = value; } Maybe Joshua could .zip the patch?
          Hide
          Joshua Bassett added a comment -

          Patch for RollingFileAppender.cs

          Show
          Joshua Bassett added a comment - Patch for RollingFileAppender.cs

            People

            • Assignee:
              Ron Grabowski
              Reporter:
              Joshua Bassett
            • Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development