-
-
Notifications
You must be signed in to change notification settings - Fork 334
RollingFileAppender overwrites an old log even if AppendToFile is true when RollingStyle is Composite and there are some logs on that day. #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I confirmed that 3.0.0-preview.2 also reproduces this issue. |
thanks for reporting. |
I found some time to dig in properly. The current codebase does not support specifying the extension in the <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value=".\Log\.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value='yyyy-MM-dd' />
<param name="MaximumFileSize" value="5MB" />
<param name="MaxSizeRollBackups" value="10" />
<param name="StaticLogFileName" value="false" />
<param name="CountDirection" value="1" />
<param name="PreserveLogFileNameExtension" value="true"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy/MM/dd HH:mm:ss.fff} [%-5p] %m (%M)%n"/>
</layout>
</appender>
<logger name="log">
<level value="debug" />
<appender-ref ref="LogFileAppender" />
</logger>
</log4net>
</configuration> This will work thanks to the
You can also use the
@FreeAndNil I'm wondering if we should add support for specifying the extension in the |
Thank you, @gdziadkiewicz, We also found the same solution before, but this time MaxSizeRollBackups is ignored and log files for the same day are created endlessly. If this is the correct solution, we think the true issue is that MaxSizeRollBackups is ignored in this case. |
Hi @WorldRobertProject , you are right. I just reproduced this bug with |
@WorldRobertProject can you test whether #232 solves your problem? |
Now when "DatePattern" is "yyyy-MM-dd", it reproduces the issue.
When "DatePattern" is 'yyyy-MM-dd".log"', it causes the following error:
|
Hi @WorldRobertProject |
Here is the setting which reproduces the issue.
Here is the test code.
We prepared the following three log files:
After we executed the test code, 2025-04-10.1.log was truncated and overwritten. |
When RollingStyle is Composite, it seems RollingFileAppender ignores AppendToFile flag except for the first log on that day.
The following code makes log files as 2024-08-02.0.log, 2024-08-02.1.log, ...
log4net.config.xml
Program.cs
When only 2024-08-02.0.log exists, it appends a new log to 2024-08-02.0.log as expected.
When both 2024-08-02.0.log and 2024-08-02.1.log exist and 2024-08-02.0.log is greater than 5MB, this code overwrites 2024-08-02.1.log and outputs the following error message:
It seems AppendToFile flag is ignored.
All log4net versions from 2.0.10 to 2.0.17 reproduce this issue.
The text was updated successfully, but these errors were encountered: