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 all log lines. /// </summary> public void Clear() { lock (_syncRoot) { if (_logEntries.Count > 0) { _logEntries.Clear(); MaxCharactersPerLine = 0; _properties.SetValue(LogFileProperties.StartTimestamp, null); _properties.SetValue(LogFileProperties.EndTimestamp, null); _properties.SetValue(LogFileProperties.Size, Size.Zero); Touch(); _listeners.Reset(); } } }