Skip to content

Sporadic duplicate-date filename during RollingFileAppender size rollover; logging sometimes stops #382

Duplicate

Description

@coder240201

RollingFileAppender: size roll sometimes writes to a file with the date twice, or overwrites the active file

Environment

  • log4net 3.3.0
  • Windows service, .NET Framework 4.8
  • RollingStyle Composite, ExclusiveLock

Configuration

<file value="C:\log\FILE.LOG" />
<preserveLogFileNameExtension value="true" />
<staticLogFileName value="false" />
<datePattern value="-yyyyMMdd" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1000MB" />
<immediateFlush value="true" />
<lockingModel type="log4net.Appender.FileAppender+ExclusiveLock" />

Expected

  • At 1000 MB, the appender renames FILE-20261202.LOG to FILE-20261202.1.LOG.
  • Logging continues in a new FILE-20261202.LOG.

Actual (sporadic, most rolls are correct, no reliable steps to reproduce)

  • Case 1: logging continues in FILE-20261202-20261202.LOG.
  • Case 2: the appender overwrites FILE-20261204.LOG. Its previous content is lost.
  • Sometimes logging stops until the server restarts. No debug output is available for this case.

Debug output, case 1

log4net:ERROR [RollingFileAppender] ErrorCode: GenericFailure. Output stream for appender named [FileLogAppender] has been closed.
log4net: Moving [C:\log\FILE-20261202.1.LOG] -> [C:\log\FILE-20261202.2.LOG]
log4net: Moving [C:\log\FILE-20261202.LOG] -> [C:\log\FILE-20261202.1.LOG]
log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\log\FILE-20261202.LOG] already exists.
log4net: Opening file for writing [C:\log\FILE-20261202.LOG] append [False]
log4net: Opening file for writing [C:\log\FILE-20261202-20261202.LOG] append [False]

Debug output, case 2

log4net: Moving [C:\log\FILE-20261204.LOG] -> [C:\log\FILE-20261204.1.LOG]
log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\log\FILE-20261204.LOG] already exists.
log4net: Opening file for writing [C:\log\FILE-20261204.LOG] append [False]

Questions

  • Is this a known issue?
  • Which version fixes it?
  • Is there a workaround?

Activity

  1. coder240201 commented on Dec 4, 2026

    @coder240201
    Author

    Additional case: active log file overwritten during roll

    • Same configuration.
    • No file with the date twice.
    • The appender overwrites the active file. Its previous content is lost.
    log4net: Moving [C:\log\FILE-20261204.LOG] -> [C:\log\FILE-20261204.1.LOG]
    log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\log\FILE-20261204.LOG] already exists.
    log4net: Opening file for writing [C:\log\FILE-20261204.LOG] append [False]
    
    • The rename does not move the file. The appender then opens it with append=false.

    Questions

    • Is this related to the first case?
    • Which version fixes it?
    • Is there a workaround to prevent the data loss?
  2. FreeAndNil commented on Dec 4, 2026

    @FreeAndNil
    Contributor

    @coder240201 Thank you for the detailed report and the debug output.

    Both effects are known and fixed:

    How it happens (both paths have unit tests):

    • The rename of FILE-20261202.LOG to FILE-20261202.1.LOG fails.
    • Its error does not show, because the default error handler reports only the first error ("Output stream ... has been closed").
    • 3.3.0 then opens the file with append=false. If the open succeeds, the file is overwritten. If it fails, the retry adds the date again.

    Recommendations:

    • Update to 3.6.0 now. This prevents the data loss.
    • Update to the next release for the file name fix.
    • Find the process that holds the log file open during the roll (for example antivirus, backup or a log shipper). Exclude the log folder from it.

    "Logging stops until restart":

    • We do not know the cause yet.
    • If this occurs on 3.6.0, please open a new issue.
    • Attach the internal debug output from the last successful roll up to the point where logging stops.
    • To enable it, see How do I enable log4net internal debugging?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions