public void LinuxLogs_ResolvesAndReadsCorrectly_WithLineSeek() { using (var reader = system.CreateWithLineCountFastForward(sampleLogFilePath, 3)) { List <string> lines = new List <string>(); string line; while ((line = reader.TryReadNextLine()) != null) { lines.Add(line); } Expect(lines[0], EqualTo("[00:08:05] Baloo is logged in on Xanadu.")); Expect(lines[24], EqualTo("[00:19:43] You are no longer invulnerable.")); } }
private void ParseMonthlyFile( CharacterMonthlyLogHeuristics heuristicsFileMap, LogFileInfo logFileInfo, List <LogEntry> result, LogFileParser logFileParser) { var heuristics = heuristicsFileMap.GetFullHeuristicsForMonth(logFileInfo); var dayToSearchFrom = GetMinDayToSearchFrom(logSearchParameters.MinDate, logFileInfo.LogFileDate.DateTime); var dayToSearchTo = GetMaxDayToSearchUpTo(logSearchParameters.MaxDate, logFileInfo.LogFileDate.DateTime); List <LogEntry> entries = new List <LogEntry>(); LogFileStreamReader reader = null; try { for (int day = dayToSearchFrom; day <= dayToSearchTo; day++) { var thisDayHeuristics = heuristics.GetForDay(day); if (thisDayHeuristics.LinesLength == 0) { continue; } if (reader == null) { if (heuristics.HasValidFilePositions) { reader = streamReaderFactory.Create( logFileInfo.FullPath, thisDayHeuristics.StartPositionInBytes); } else { reader = streamReaderFactory.CreateWithLineCountFastForward( logFileInfo.FullPath, thisDayHeuristics.TotalLinesSinceBeginFile); } } var thisEntryDate = new DateTime( logFileInfo.LogFileDate.DateTime.Year, logFileInfo.LogFileDate.DateTime.Month, day, 0, 0, 0); int readLinesCount = 0; List <string> allLines = new List <string>(); string currentLine; while ((currentLine = reader.TryReadNextLine()) != null) { allLines.Add(currentLine); readLinesCount++; if (readLinesCount == thisDayHeuristics.LinesLength) { break; } } IList <LogEntry> parsedLines = logFileParser.ParseLinesForDay(allLines, thisEntryDate, logFileInfo); entries.AddRange(parsedLines); cancellationManager.ThrowIfCancelled(); } result.AddRange(entries); } finally { reader?.Dispose(); } }