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

RollArchivesForward() private method

Archives the fileName using a rolling style numbering (the most recent is always #0 then #1, ..., #N. When the number of archive files exceed P:MaxArchiveFiles the obsolete archives are deleted.
This method is called recursively. This is the reason the archiveNumber is required.
private RollArchivesForward ( string fileName, string pattern, int archiveNumber ) : void
fileName string File name to be archived.
pattern string File name template which contains the numeric pattern to be replaced.
archiveNumber int Value which will replace the numeric pattern.
return void
        private void RollArchivesForward(string fileName, string pattern, int archiveNumber)
        {
            if (ShouldDeleteOldArchives() && archiveNumber >= this.MaxArchiveFiles)
            {
                DeleteOldArchiveFile(fileName);
                return;
            }

            if (!File.Exists(fileName))
            {
                return;
            }

            string newFileName = ReplaceNumberPattern(pattern, archiveNumber);
            RollArchivesForward(newFileName, pattern, archiveNumber + 1);

            if (archiveNumber == 0)
                ArchiveFile(fileName, newFileName);
            else
            {
                InternalLogger.Info("Roll archive {0} to {1}", fileName, newFileName);
                File.Move(fileName, newFileName);
            }
        }