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

GetArchiveFileNameBasedOnTime() private method

Returns the file name for archiving, or null if archiving should not occur based on date/time.
private GetArchiveFileNameBasedOnTime ( string fileName, LogEventInfo logEvent ) : string
fileName string File name to be written.
logEvent LogEventInfo Log event that the instance is currently processing.
return string
        private string GetArchiveFileNameBasedOnTime(string fileName, LogEventInfo logEvent)
        {
            if (this.ArchiveEvery == FileArchivePeriod.None)
            {
                return null;
            }

            fileName = GetPotentialFileForArchiving(fileName);

            if (fileName == null)
            {
                return null;
            }

            var creationTimeUtc = this.fileAppenderCache.GetFileCreationTimeUtc(fileName, true);
            if (creationTimeUtc == null)
            {
                return null;
            }

            // file creation time is in Utc and logEvent's timestamp is originated from TimeSource.Current,
            // so we should ask the TimeSource to convert file time to TimeSource time:

            DateTime creationTime = TimeSource.Current.FromSystemTime(creationTimeUtc.Value);
            string formatString = GetArchiveDateFormatString(string.Empty);
            string fileCreated = creationTime.ToString(formatString, CultureInfo.InvariantCulture);
            string logEventRecorded = logEvent.TimeStamp.ToString(formatString, CultureInfo.InvariantCulture);

            var shouldArchive = fileCreated != logEventRecorded;
            if (shouldArchive)
            {
                return fileName;
            }
            return null;
        }