public override IEnumerable <LogEntry> GetLogEntries(DateTime timeFrom, DateTime timeTo) { Verify.That(timeFrom <= timeTo, "An incorrect time interval given."); string filePath; LogEntry[] newEntries; lock (_fileLogger.SyncRoot) { var fileConn = _fileLogger.FileConnection; newEntries = fileConn.NewEntries.ToArray(); filePath = fileConn.FilePath; } DateTime readUntil = newEntries.FirstOrDefault()?.TimeStamp.AddMilliseconds(-1) ?? DateTime.Now; if (timeFrom <= readUntil) { using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var parserEnumerable = LogReaderHelper.ParseLogLines(fs); foreach (var logEntry in parserEnumerable) { if (logEntry.TimeStamp < timeFrom) { continue; } if (logEntry.TimeStamp > timeTo || logEntry.TimeStamp > readUntil) { break; } yield return(logEntry); } } } foreach (var logEntry in newEntries) { if (logEntry.TimeStamp < timeFrom) { continue; } if (logEntry.TimeStamp > timeTo) { break; } yield return(logEntry); } }
public override IEnumerable <LogEntry> GetLogEntries(DateTime timeFrom, DateTime timeFromTo) { var logLines = LogReaderHelper.GetLinesEnumerable(_file); return(LogReaderHelper.ParseLogLines(logLines)); }