Copilot commented on code in PR #319:
URL: https://github.com/apache/logging-log4net/pull/319#discussion_r4060944089


##########
src/log4net/Appender/RollingFileAppender.cs:
##########
@@ -1114,7 +1157,10 @@ protected void RollOverTime(bool fileIsOpen)
         RollFile(from, to);
       }
 
-      RollFile(File!, _scheduledFilename!);
+      if (!TryRollFile(File!, _scheduledFilename!))
+      {
+        RecordFailedBaseRename(File!, _scheduledFilename!, 
wasBackupCountReverted: false);
+      }

Review Comment:
   When this failure occurs during `ExistingInit()` with `AppendToFile == 
false` and `MaxSizeRollBackups != 0`, initialization continues to 
`RollOverRenameFiles(fileName)`. That second rollover either replaces this 
pending date rename or successfully moves its source to `.1` while this stale 
pending rename remains; the first retry can then archive the newly created 
current file under the previous date. Stop the startup path from performing the 
second rollover once a pending date rename has been recorded.



##########
src/log4net/Appender/RollingFileAppender.cs:
##########
@@ -587,6 +614,12 @@ protected override void OpenFile(string fileName, bool 
append)
     {
       fileName = GetNextOutputFileName(fileName);
 
+      // A rename that failed left its file where it was. Never truncate that 
one, whatever
+      // AppendToFile says, or the roll destroys what it could not move.
+      append = append
+        || (_pendingRename is not null
+          && string.Equals(fileName, _pendingRename.From, 
StringComparison.Ordinal));

Review Comment:
   This forced `append = true` is passed to `FileAppender.OpenFile`, which 
assigns it back to the public `AppendToFile` property. A failed startup roll 
therefore silently changes a configured `AppendToFile = false` to true; if 
options are reactivated while the rename is still pending, `_pendingRename` is 
cleared and the requested startup rollover is skipped. Preserve the configured 
property value while using append semantics only for this reopen.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to