internal static LogFileInfo GetLatestOrNew(DateTime date, string logDirectory) { string pattern; var logFileInfo = new LogFileInfo(date, 1); if (logFileInfo.ProcessId == 0) { pattern = date.ToString(DateFormat) + @"-(\d{5}).log"; } else { pattern = string.Format("{0}-{1}-{2}-{3}.log", date.ToString(DateFormat), logFileInfo.ProcessId, logFileInfo.ProcessName, @"(\d{5})"); } foreach (var filePath in Directory.GetFiles(logDirectory)) { Match match = Regex.Match(filePath, pattern); if (match.Success) { var sequence = uint.Parse(match.Groups[1].Value); if (sequence > logFileInfo.Sequence) { logFileInfo = new LogFileInfo(date, sequence); } } } return logFileInfo; }
private SizeLimitedFileSink GetLatestSink() { EnsureDirectoryCreated(this.logDirectory); LogFileInfo logFileInfo = LogFileInfo.GetLatestOrNew(DateTime.UtcNow, this.logDirectory); return(new SizeLimitedFileSink( this.formatter, this.logDirectory, new SizeLimitedLogFileDescription(logFileInfo, this.fileSizeLimitBytes), this.encoding)); }
internal static LogFileInfo GetLatestOrNew(DateTime date, string logDirectory) { string pattern = date.ToString(DateFormat) + @"-(\d{5}).log"; var logFileInfo = new LogFileInfo(date, 1); foreach (var filePath in Directory.GetFiles(logDirectory)) { Match match = Regex.Match(filePath, pattern); if (match.Success) { var sequence = uint.Parse(match.Groups[1].Value); if (sequence > logFileInfo.Sequence) { logFileInfo = new LogFileInfo(date, sequence); } } } return(logFileInfo); }