in src/log4net/Appender/RollingFileAppender.cs [923:1001]
private void InitializeFromOneFile(string baseFile, string curFileName)
{
curFileName = curFileName.ToLower();
baseFile = baseFile.ToLower();
if (curFileName.StartsWith(Path.GetFileNameWithoutExtension(baseFile)) == false)
{
// This is not a log file, so ignore
return;
}
if (curFileName.Equals(baseFile))
{
// Base log file is not an incremented logfile (.1 or .2, etc)
return;
}
// Only look for files in the current roll point
if (m_rollDate && !m_staticLogFileName)
{
var date = m_dateTime.Now.ToString(m_datePattern, DateTimeFormatInfo.InvariantInfo).ToLower();
var prefix = (m_preserveLogFileNameExtension
? Path.GetFileNameWithoutExtension(baseFile) + date
: baseFile + date).ToLower();
var suffix = m_preserveLogFileNameExtension
? Path.GetExtension(baseFile).ToLower()
: "";
if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
{
LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"] because it is from a different date period");
return;
}
}
try
{
// Bump the counter up to the highest count seen so far
var backup = GetBackUpIndex(curFileName);
// caution: we might get a false positive when certain
// date patterns such as yyyyMMdd are used...those are
// valid number but aren't the kind of back up index
// we're looking for
if (backup > m_curSizeRollBackups)
{
if (0 == m_maxSizeRollBackups)
{
// Stay at zero when zero backups are desired
}
else if (-1 == m_maxSizeRollBackups)
{
// Infinite backups, so go as high as the highest value
m_curSizeRollBackups = backup;
}
else
{
// Backups limited to a finite number
if (m_countDirection >= 0)
{
// Go with the highest file when counting up
m_curSizeRollBackups = backup;
}
else
{
// Clip to the limit when counting down
if (backup <= m_maxSizeRollBackups)
{
m_curSizeRollBackups = backup;
}
}
}
LogLog.Debug(declaringType, "File name [" + curFileName + "] moves current count to [" + m_curSizeRollBackups + "]");
}
}
catch(FormatException)
{
//this happens when file.log -> file.log.yyyy-MM-dd which is normal
//when staticLogFileName == false
LogLog.Debug(declaringType, "Encountered a backup file not ending in .x ["+curFileName+"]");
}
}