private void Run() { try { do { List <TailLine> newLines = new List <TailLine>(); foreach (var file in _tailFiles) { newLines.AddRange(file.ReadNewLines()); } if (newLines.Count > 0) { _tailModel.AddLines(newLines); } }while (!_exitHandle.WaitOne(100)); } catch (Exception ex) { var errorLine = new TailLine( DateTime.Now, String.Empty, "Local", Brushes.Red, "Exception reading log: " + ex); _tailModel.AddLine(errorLine); } }
public List <TailLine> ReadNewLines() { List <TailLine> newLines = new List <TailLine>(); if (!Monitor.TryEnter(_readLock)) { return(newLines); } try { // use >= in case file was truncated or lines were removed if (_lastMaxOffset >= _reader.BaseStream.Length) { return(newLines); } _reader.BaseStream.Seek(_lastMaxOffset, SeekOrigin.Begin); string line; while ((line = _reader.ReadLine()) != null) { var dateMatch = _dateRegex.Match(line); if (dateMatch.Success) { _lastLineDateTime = DateTime.Parse(dateMatch.Groups[0].Captures[0].ToString()); } var tailLine = new TailLine( _lastLineDateTime, _fileFolder, _fileName, _bgBrush, line); _tailLines.Add(tailLine); newLines.Add(tailLine); } _lastMaxOffset = _reader.BaseStream.Position; return(newLines); } finally { Monitor.Exit(_readLock); } }
private void Run() { try { do { List<TailLine> newLines = new List<TailLine>(); foreach (var file in _tailFiles) newLines.AddRange(file.ReadNewLines()); if (newLines.Count > 0) _tailModel.AddLines(newLines); } while (!_exitHandle.WaitOne(100)); } catch (Exception ex) { var errorLine = new TailLine( DateTime.Now, String.Empty, "Local", Brushes.Red, "Exception reading log: " + ex); _tailModel.AddLine(errorLine); } }
public List<TailLine> ReadNewLines() { List<TailLine> newLines = new List<TailLine>(); if (!Monitor.TryEnter(_readLock)) return newLines; try { // use >= in case file was truncated or lines were removed if (_lastMaxOffset >= _reader.BaseStream.Length) return newLines; _reader.BaseStream.Seek(_lastMaxOffset, SeekOrigin.Begin); string line; while ((line = _reader.ReadLine()) != null) { var dateMatch = _dateRegex.Match(line); if (dateMatch.Success) _lastLineDateTime = DateTime.Parse(dateMatch.Groups[0].Captures[0].ToString()); var tailLine = new TailLine( _lastLineDateTime, _fileFolder, _fileName, _bgBrush, line); _tailLines.Add(tailLine); newLines.Add(tailLine); } _lastMaxOffset = _reader.BaseStream.Position; return newLines; } finally { Monitor.Exit(_readLock); } }
public void AddLine(TailLine line) { AddLines(new [] { line }); }
public void AddLine(TailLine line) { AddLines(new []{ line }); }