private void DoAutoArchive(string fileName, LogEventInfo eventInfo)
{
var fileInfo = new FileInfo(fileName);
if (!fileInfo.Exists)
{
// Close possible stale file handles
this.fileAppenderCache.InvalidateAppender(fileName);
this.initializedFiles.Remove(fileName);
return;
}
string fileNamePattern = GetArchiveFileNamePattern(fileName, eventInfo);
if (fileNamePattern == null)
{
InternalLogger.Warn("Skip auto archive because fileName is NULL");
return;
}
if (!ContainsFileNamePattern(fileNamePattern))
{
if (fileArchive.Archive(fileNamePattern, fileInfo.FullName, CreateDirs))
{
if (this.initializedFiles.ContainsKey(fileInfo.FullName))
{
this.initializedFiles.Remove(fileInfo.FullName);
}
}
}
else
{
switch (this.ArchiveNumbering)
{
case ArchiveNumberingMode.Rolling:
this.RollArchivesForward(fileInfo.FullName, fileNamePattern, 0);
break;
case ArchiveNumberingMode.Sequence:
this.ArchiveBySequence(fileInfo.FullName, fileNamePattern);
break;
#if !NET_CF
case ArchiveNumberingMode.Date:
this.ArchiveByDate(fileInfo.FullName, fileNamePattern, eventInfo);
break;
case ArchiveNumberingMode.DateAndSequence:
this.ArchiveByDateAndSequence(fileInfo.FullName, fileNamePattern, eventInfo);
break;
#endif
}
}
}