<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.6" />

ObservableUpDownCounter<T>

public sealed class ObservableUpDownCounter<T> : ObservableInstrument<T> where T : struct
A metrics-observable instrument that reports increasing or decreasing values when the instrument is being observed. Use this instrument to monitor the process heap size or the approximate number of items in a lock-free circular buffer, for example. To create an ObservableUpDownCounter object, use the CreateObservableUpDownCounter methods.
using System.Collections.Generic; using System.Runtime.CompilerServices; namespace System.Diagnostics.Metrics { public sealed class ObservableUpDownCounter<T> : ObservableInstrument<T> where T : struct { private readonly object _callback; internal ObservableUpDownCounter(Meter meter, string name, Func<T> observeValue, string unit, string description) : this(meter, name, observeValue, unit, description, (IEnumerable<KeyValuePair<string, object>>)null) { } internal ObservableUpDownCounter(Meter meter, string name, Func<T> observeValue, string unit, string description, IEnumerable<KeyValuePair<string, object>> tags) : base(meter, name, unit, description, tags) { if (observeValue == null) throw new ArgumentNullException("observeValue"); _callback = observeValue; Publish(); } internal ObservableUpDownCounter(Meter meter, string name, Func<Measurement<T>> observeValue, string unit, string description) : this(meter, name, observeValue, unit, description, (IEnumerable<KeyValuePair<string, object>>)null) { } internal ObservableUpDownCounter(Meter meter, string name, Func<Measurement<T>> observeValue, string unit, string description, IEnumerable<KeyValuePair<string, object>> tags) : base(meter, name, unit, description, tags) { if (observeValue == null) throw new ArgumentNullException("observeValue"); _callback = observeValue; Publish(); } internal ObservableUpDownCounter(Meter meter, string name, Func<IEnumerable<Measurement<T>>> observeValues, string unit, string description) : this(meter, name, observeValues, unit, description, (IEnumerable<KeyValuePair<string, object>>)null) { } internal ObservableUpDownCounter(Meter meter, string name, Func<IEnumerable<Measurement<T>>> observeValues, string unit, string description, IEnumerable<KeyValuePair<string, object>> tags) : base(meter, name, unit, description, tags) { if (observeValues == null) throw new ArgumentNullException("observeValues"); _callback = observeValues; Publish(); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0, 0 })] protected override IEnumerable<Measurement<T>> Observe() { return ObservableInstrument<T>.Observe(_callback); } } }