private TimeSpan RunOnce() { bool performedWork = false; KeyValuePair <ILogFile, LogFileSection> pair; while (_pendingSections.TryDequeue(out pair)) { var sender = pair.Key; var innerLogFile = _innerLogFile; var section = pair.Value; if (sender != innerLogFile) { // If, for some reason, we receive an event from a previous log file, // then we ignore it so our listeners are not confused. Log.DebugFormat( "Skipping pending modification '{0}' from '{1}' because it is no longer our current log file '{2}'", section, sender, innerLogFile); } else { if (section.IsReset) { _listeners.Reset(); } else if (section.IsInvalidate) { _listeners.Invalidate((int)section.Index, section.Count); } else { _listeners.OnRead((int)(section.Index + section.Count)); } } performedWork = true; } // This line is extremely important because listeners are allowed to limit how often they are notified. // This means that even when there is NO modification to the source, we still need to notify the collection // so it can check if enough time has ellapsed to finally notify listener. _listeners.OnRead(_listeners.CurrentLineIndex); if (performedWork) { return(TimeSpan.Zero); } return(TimeSpan.FromMilliseconds(10)); }
/// <summary> /// Removes everything from the given index onwards until the end. /// </summary> /// <param name="index"></param> public void RemoveFrom(LogLineIndex index) { lock (_syncRoot) { if (index < 0) { Log.WarnFormat("Invalid index '{0}'", index); return; } if (index > _logEntries.Count) { Log.WarnFormat("Invalid index '{0}', Count is '{1}'", index, _logEntries.Count); return; } var available = _logEntries.Count - index; _logEntries.RemoveRange((int)index, available); _listeners.Invalidate((int)index, available); Touch(); } }