public PathRoller(string path, RollingInterval interval) { if (path == null) { throw new ArgumentNullException(nameof(path)); } _interval = interval; _periodFormat = interval.GetFormat(); var pathDirectory = Path.GetDirectoryName(path); if (string.IsNullOrEmpty(pathDirectory)) { pathDirectory = Directory.GetCurrentDirectory(); } _directory = Path.GetFullPath(pathDirectory); _filenamePrefix = Path.GetFileNameWithoutExtension(path); _filenameSuffix = Path.GetExtension(path); _filenameMatcher = new Regex( "^" + Regex.Escape(_filenamePrefix) + "(?<" + PeriodMatchGroup + ">\\d{" + _periodFormat.Length + "})" + "(?<" + SequenceNumberMatchGroup + ">_[0-9]{3,}){0,1}" + Regex.Escape(_filenameSuffix) + "$"); DirectorySearchPattern = $"{_filenamePrefix}*{_filenameSuffix}"; }
private string GetRealTargetPath(ILogEventInfo logEventInfo) { var indexOfLastPoint = _path.LastIndexOf('.'); return(indexOfLastPoint < 0 ? $"{_path}{logEventInfo.Timestamp.DateTime.ToString(_rolling.GetFormat())}" : $"{_path.Substring(0, indexOfLastPoint)}{logEventInfo.Timestamp.DateTime.ToString(_rolling.GetFormat())}.{_path.Substring(indexOfLastPoint + 1)}"); }