<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="10.0.0-preview.6.25358.103" />

UpDownCounter<T>

public sealed class UpDownCounter<T> : Instrument<T> where T : struct
An instrument that supports reporting positive or negative metric values. UpDownCounter may be used in scenarios like reporting the change in active requests or queue size.
using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Diagnostics.Metrics { public sealed class UpDownCounter<T> : Instrument<T> where T : struct { internal UpDownCounter(Meter meter, string name, string unit, string description) : this(meter, name, unit, description, (IEnumerable<KeyValuePair<string, object>>)null) { } internal UpDownCounter(Meter meter, string name, string unit, string description, IEnumerable<KeyValuePair<string, object>> tags) : base(meter, name, unit, description, tags) { Publish(); } public void Add(T delta) { RecordMeasurement(delta); } public void Add(T delta, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag) { RecordMeasurement(delta, tag); } public void Add(T delta, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2) { RecordMeasurement(delta, tag1, tag2); } public void Add(T delta, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag3) { RecordMeasurement(delta, tag1, tag2, tag3); } public void Add(T delta, [System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1, 2 })] ReadOnlySpan<KeyValuePair<string, object>> tags) { RecordMeasurement(delta, tags); } public void Add(T delta, [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0, 1, 2 })] params KeyValuePair<string, object>[] tags) { RecordMeasurement(delta, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(tags)); } public void Add(T delta, [In] [System.Runtime.CompilerServices.IsReadOnly] ref TagList tagList) { RecordMeasurement(delta, ref tagList); } } }