in src/log4net/Appender/RollingFileAppender.cs [1058:1107]
protected void RollOverTime(bool fileIsOpen)
{
if (StaticLogFileName)
{
// Compute filename, but only if datePattern is specified
if (DatePattern is null)
{
ErrorHandler.Error("Missing DatePattern option in rollOver().");
return;
}
//is the new file name equivalent to the 'current' one
//something has gone wrong if we hit this -- we should only
//roll over if the new file will be different from the old
string dateFormat = _now.ToString(DatePattern, DateTimeFormatInfo.InvariantInfo);
if (string.Equals(_scheduledFilename, CombinePath(File!, dateFormat), StringComparison.Ordinal))
{
ErrorHandler.Error($"Compare {_scheduledFilename} : {CombinePath(File!, dateFormat)}");
return;
}
if (fileIsOpen)
{
// close current file, and rename it to datedFilename
CloseFile();
}
//we may have to roll over a large number of backups here
for (int i = 1; i <= CurrentSizeRollBackups; i++)
{
string from = CombinePath(File!, "." + i);
string to = CombinePath(_scheduledFilename!, "." + i);
RollFile(from, to);
}
RollFile(File!, _scheduledFilename!);
}
//We've cleared out the old date and are ready for the new
CurrentSizeRollBackups = 0;
//new scheduled name
_scheduledFilename = CombinePath(File!, _now.ToString(DatePattern, DateTimeFormatInfo.InvariantInfo));
if (fileIsOpen)
{
// This will also close the file. This is OK since multiple close operations are safe.
SafeOpenFile(_baseFileName!, false);
}
}