public IEnumerable <string> GetLinesSinceLastKnownLine() { if (!string.IsNullOrEmpty(_logFilePath)) { using (Stream stream = File.Open(_logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (stream != null) { ReverseLineReader line = new ReverseLineReader(() => stream); // create anonymous method to return Stream as Func<Stream> if (string.IsNullOrEmpty(lastKnownLine)) { var latestLine = line.Take(1).ToList(); lastKnownLine = latestLine.First(); return(latestLine); } var newChatLines = line.Take(15).ToList(); var indexOfLastKnownLine = newChatLines.IndexOf(lastKnownLine); lastKnownLine = newChatLines.First(); if (indexOfLastKnownLine >= 0) { return(newChatLines.Take(indexOfLastKnownLine)); } return(newChatLines); } } } return(new List <string> { "404 -> Logfile not found!" }); }
private void checkForUpdates(string debug = null) { fileTimer.Stop(); var reverseReader = new ReverseLineReader(clientLogPath + "\\client.txt"); var lines = reverseReader.Take(50).ToList(); if (lastLines == null) { lastLines = lines; } else { var newLines = lines.Except(lastLines).ToList(); lastLines = lines; foreach (var line in newLines) { Message message = new Message(line); NewMessage(null, new MessageEventArgs(message)); } } fileTimer.Start(); }
private void InitLastLogLineAsLastKnownLine() { if (!string.IsNullOrEmpty(_logFilePath)) { using (Stream stream = File.Open(_logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (stream != null) { ReverseLineReader line = new ReverseLineReader(() => stream); // create anonymous method to return Stream as Func<Stream> if (string.IsNullOrEmpty(lastKnownLine)) { var latestLine = line.Take(1).ToList(); lastKnownLine = latestLine.First(); } } } } }