private TimeSpan RunOnce() { bool performedWork = false; //while (_pendingSections.TryDequeue(out var pair)) if (_pendingSections.TryDequeueUpTo(_maxEntryCount, out var pendingModifications)) { foreach (var pair in pendingModifications) { var sender = pair.Key; var innerLogFile = _source; var modification = 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}'", modification, sender, innerLogFile); } else { if (modification.IsReset()) { _listeners.Reset(); } else if (modification.IsRemoved(out var removedSection)) { _listeners.Remove((int)removedSection.Index, removedSection.Count); } else if (modification.IsAppended(out var appendedSection)) { _listeners.OnRead((int)(appendedSection.Index + appendedSection.Count)); } } performedWork = true; } } UpdateProperties(); // 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 elapsed to finally notify listener. _listeners.OnRead(_listeners.CurrentLineIndex); if (performedWork) { return(TimeSpan.Zero); } return(TimeSpan.FromMilliseconds(10)); }
/// <summary> /// Removes all log lines. /// </summary> public void Clear() { lock (_syncRoot) { if (_logBuffer.Count > 0) { _logBuffer.Clear(); SetValue(Core.Properties.LogEntryCount, _logBuffer.Count); _properties.SetValue(TextProperties.MaxCharactersInLine, 0); _properties.SetValue(Core.Properties.StartTimestamp, null); _properties.SetValue(Core.Properties.EndTimestamp, null); _properties.SetValue(Core.Properties.Size, Size.Zero); Touch(); _listeners.Reset(); } } }