/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/core/diagnostics/snippets/EventCounters/RequestEventSource.cs
27 строк
766 B
Günther Foidl
Note for torn-reads in EventCounters (#20984)
09 окт 2020, 20:24
Не верифицирован
09 окт 2020, 20:24
c77eae3
Код
Авторство
О чём код?
using System; using System.Diagnostics.Tracing; public class RequestEventSource : EventSource { public static readonly RequestEventSource Log = new RequestEventSource(); private IncrementingPollingCounter _requestRateCounter; private long _requestCount = 0; private RequestEventSource() => _requestRateCounter = new IncrementingPollingCounter("request-rate", this, () => _requestCount) { DisplayName = "Request Rate", DisplayRateTimeScale = TimeSpan.FromSeconds(1) }; public void AddRequest() => ++ _requestCount; protected override void Dispose(bool disposing) { _requestRateCounter?.Dispose(); _requestRateCounter = null; base.Dispose(disposing); } }