ComposeFileName() public static method

public static ComposeFileName ( string file, System.DateTime date ) : string
file string
date System.DateTime
return string
Beispiel #1
0
        private void RollOverIfDateBoundaryCrossing()
        {
            if (!_staticLogFileName || !_rollDate || !FileExists(_baseFileName))
            {
                return;
            }

            DateTime lastWriteTime;

            using (SecurityContext.Impersonate(this))
            {
                lastWriteTime = System.IO.File.GetLastWriteTime(_baseFileName);
            }

            LogLog.Debug("RollingFileAppender: [" +
                         lastWriteTime.ToString(ActivityLogFile.FileDatePattern, DateTimeFormatInfo.InvariantInfo) + "] vs. [" +
                         _now.ToString(ActivityLogFile.FileDatePattern, DateTimeFormatInfo.InvariantInfo) + "]");
            if (lastWriteTime.ToString(ActivityLogFile.FileDatePattern, DateTimeFormatInfo.InvariantInfo)
                .Equals(_now.ToString(ActivityLogFile.FileDatePattern, DateTimeFormatInfo.InvariantInfo)))
            {
                return;
            }

            _scheduledFilename = ActivityLogFile.ComposeFileName(_baseFileName, lastWriteTime);
            LogLog.Debug("RollingFileAppender: Initial roll over to [" + _scheduledFilename + "]");
            RollOverTime(false);
            LogLog.Debug("RollingFileAppender: curSizeRollBackups after rollOver at [" + _curSizeRollBackups + "]");
        }
Beispiel #2
0
        protected string GetNextOutputFileName(string fileName)
        {
            using (SecurityContext.Impersonate(this))
            {
                if (!_staticLogFileName)
                {
                    fileName = fileName.Trim();
                    if (_rollDate)
                    {
                        fileName = ActivityLogFile.ComposeFileName(fileName, _now);
                    }
                    if (_countDirection >= 0)
                    {
                        fileName = ActivityLogFile.ComposeFileName(fileName, _dateTime.Now) + '.' + _curSizeRollBackups;
                    }
                }
            }

            return(fileName);
        }
Beispiel #3
0
        protected void RollOverTime(bool fileIsOpen)
        {
            if (_staticLogFileName)
            {
                string str = _now.ToString(ActivityLogFile.FileDatePattern, DateTimeFormatInfo.InvariantInfo);

                if (_scheduledFilename.Equals(File + str))
                {
                    ErrorHandler.Error("Compare " + _scheduledFilename + " : " + File + str);
                    return;
                }

                if (fileIsOpen)
                {
                    CloseFile();
                }

                for (int index = 1; index <= _curSizeRollBackups; ++index)
                {
                    RollFile(File + '.' + index, _scheduledFilename + '.' + index);
                }

                RollFile(File, _scheduledFilename);
            }

            _curSizeRollBackups = 0;

            using (SecurityContext.Impersonate(this))
            {
                _scheduledFilename = ActivityLogFile.ComposeFileName(File, _now);
            }

            if (!fileIsOpen)
            {
                return;
            }

            SafeOpenFile(_baseFileName, false);
        }
Beispiel #4
0
        public override void ActivateOptions()
        {
            if (IsTemplate)
            {
                return;
            }

            _now       = _dateTime.Now;
            _rollPoint = ComputeCheckPeriod(ActivityLogFile.FileDatePattern);
            if (_rollPoint == RollPoint.InvalidRollPoint)
            {
                throw new ArgumentException("Invalid RollPoint, unable to parse [" + ActivityLogFile.FileDatePattern + "]");
            }
            _nextCheck = NextCheckDate(_now, _rollPoint);

            if (SecurityContext == null)
            {
                SecurityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
            }

            using (SecurityContext.Impersonate(this))
            {
                File = ConvertToFullPath(File.Trim());

                _baseFileName = File;
            }

            if (_rollDate && File != null && _scheduledFilename == null)
            {
                _scheduledFilename = ActivityLogFile.ComposeFileName(File, _now);
            }

            ExistingInit();

            base.ActivateOptions();

            Folder = ConvertToFullPath(Folder);
            Closed = false;
        }
Beispiel #5
0
        protected void RollOverRenameFiles(string baseFileName, DateTime timeStamp)
        {
            if (_maxSizeRollBackups == 0)
            {
                return;
            }

            FileInfo[] logFiles;
            string     directoryName;
            string     backupFileName;

            using (SecurityContext.Impersonate(this))
            {
                directoryName = baseFileName.GetDirectoryName();
                logFiles      = new DirectoryInfo(directoryName)
                                .GetFiles(ActivityLogFile.GetWildcartPatternFor(baseFileName))
                                .OrderBy(x => ActivityLogFile.GetOrder(x.Name))
                                .ToArray();
                backupFileName = ActivityLogFile.ComposeFileName(baseFileName, timeStamp);
            }

            if (_countDirection < 0)
            {
                if (_curSizeRollBackups == _maxSizeRollBackups)
                {
                    DeleteFile(logFiles[_maxSizeRollBackups - 1].FullName);
                    --_curSizeRollBackups;
                }

                for (int index = _curSizeRollBackups; index > 0; --index)
                {
                    FileInfo file = logFiles[index];
                    string   newFileName;

                    using (SecurityContext.Impersonate(this))
                    {
                        newFileName = file.Name.GetFileNameWithoutExtension() + '.' + (index + 1);
                    }

                    RollFile(file.FullName, directoryName.Combine(newFileName));
                }

                ++_curSizeRollBackups;

                RollFile(baseFileName, directoryName.Combine(backupFileName + ".1"));
            }
            else
            {
                if (_curSizeRollBackups >= _maxSizeRollBackups && _maxSizeRollBackups > 0)
                {
                    int num = _curSizeRollBackups - _maxSizeRollBackups;

                    if (_staticLogFileName)
                    {
                        ++num;
                    }

                    DeleteFile(logFiles[num].FullName);
                }

                if (_staticLogFileName)
                {
                    ++_curSizeRollBackups;

                    RollFile(baseFileName, backupFileName + '.' + _curSizeRollBackups);
                }
            }
        }