NLog.Targets.FileTarget.DoAutoArchive C# (CSharp) Method

DoAutoArchive() private method

Invokes the archiving process after determining when and which type of archiving is required.
private DoAutoArchive ( string fileName, LogEventInfo eventInfo ) : void
fileName string File name to be checked and archived.
eventInfo LogEventInfo Log event that the instance is currently processing.
return void
        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
                }
            }
        }