/// <summary> /// Adds a critical, unexpected error. /// </summary> /// <param name="comment">Comment associated to the error (such as the name of the culprit). Can be null.</param> /// <param name="ex">The unexpected exception. Must not be null.</param> public void Add(Exception ex, string comment) { if (ex == null) { throw new ArgumentNullException("ex"); } if (_lostErrorCount > 1024) { return; } if (comment == null) { comment = String.Empty; } lock ( _collector ) { if (_waitingRaiseCount >= _collector.Capacity) { Interlocked.Increment(ref _lostErrorCount); return; } Interlocked.Increment(ref _waitingRaiseCount); _collector.Push(new Error(comment, ex, _seqNumber++, _lostErrorCount)); } if (Interlocked.CompareExchange(ref _dispatchWorkItemIsReady, 1, 0) == 0) { Interlocked.Increment(ref _dispatchQueuedWorkItemCount); ThreadPool.QueueUserWorkItem(DoRaiseInBackground); } else { Interlocked.Increment(ref _savedDispatchQueuedWorkItemCount); } }
/// <summary> /// Appends any log with level equal or above <see cref="MinimalFilter"/> to <see cref="Entries"/>. /// </summary> /// <param name="data">Log data. Never null.</param> void IActivityMonitorClient.OnUnfilteredLog(ActivityMonitorLogData data) { var level = data.Level & LogLevel.Mask; if ((int)level >= (int)_filter) { _entries.Push(new Entry(data.Tags, level, data.Text, data.LogTime, data.Exception)); } }
/// <summary> /// Appends any log with level equal or above <see cref="LevelFilter"/> to <see cref="Entries"/>. /// </summary> /// <param name="level">Level of the log.</param> /// <param name="text">Text of the log.</param> protected override void OnUnfilteredLog(LogLevel level, string text) { if ((int)level >= (int)_filter) { _entries.Push(new Entry() { Level = level, Text = text }); } }