FreeAndNil commented on code in PR #336:
URL: https://github.com/apache/logging-log4net/pull/336#discussion_r4242713038


##########
src/log4net/Appender/RollingFileAppender.cs:
##########
@@ -1000,6 +1012,37 @@ public void InitializeRollBackups(string baseFile, 
IList<string> arrayFiles)
     }
   }
 
+  /// <summary>
+  /// With a static name, a date that formats as a dot and up to four digits 
(<c>.dd</c> writes
+  /// <c>.10</c>) is also the name of backup 10. Counting down to a limit 
below the smallest such
+  /// name never reaches it.
+  /// </summary>
+  private bool DoesDatePatternCollideWithBackupNames()
+  {
+    if (DatePattern is not string datePattern || !IsBaseFileRolledByDate() || 
!HasNumberedBackups())
+    {
+      return false;
+    }
+
+    string sample = _sDate1970.ToString(datePattern, 
DateTimeFormatInfo.InvariantInfo);
+    return IsDotAndUpToFourDigits(sample) && CanBackupNumberEqualDate(sample);

Review Comment:
   The 1970 sample is the narrowest formatting of every numeric field except 
12-hour `h`, which is unusable without `tt`. `.Md` over-reports a count-down 
limit of exactly 10, accepted for an ambiguous pattern. The five-digit 
threshold is where `IsDateSuffix` stops counting dated files as backups, so 
detection and counting agree. The advice now names a separator only, see 
8590be00.



##########
src/changelog/3.5.1/335-short-date-pattern-collides-with-backup-names.xml:
##########
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="335" link="https://github.com/apache/logging-log4net/issues/335"/>
+  <description format="asciidoc">With `StaticLogFileName` a `DatePattern` such 
as `.dd` named dated
+  files like numbered backups, so a roll could overwrite one with the other. 
Such an appender is now
+  reported when activated and uses the dated file name as with 
`StaticLogFileName` false, so its
+  backups are numbered after the date, and an existing static file is left 
untouched, including
+  its numbered backups. Use a
+  `DatePattern` with a separator or at least five digits to keep the static 
name (reported by

Review Comment:
   Changed to recommend a separator, with the default `.yyyy-MM-dd` as the 
example, see 8590be00.



##########
src/site/antora/modules/ROOT/pages/manual/configuration/appenders/rollingfileappender.adoc:
##########
@@ -88,6 +88,13 @@ For each day only the last 10 files of 1MB will be kept.
 </appender>
 ----
 
+[NOTE]
+====
+With `staticLogFileName` a `datePattern` that formats as a dot and up to four 
digits, such as `.dd`, names dated files like numbered backups.
+Such an appender is reported when activated and uses the dated file name as 
with `staticLogFileName` false, so its backups are numbered after the date.
+Use a pattern with a separator or at least five digits to keep the static name.

Review Comment:
   Changed to recommend a separator, with the default `.yyyy-MM-dd` as the 
example, see 8590be00.



-- 
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