Table of Contents

Class EventReporter

Namespace
VpnHood.Net.Toolkit.Utils
Assembly
VpnHood.Net.Toolkit.dll

Provides a counter of a repeated event that logs a summary at an interval instead of a line per event: the message, the events since the last report, their span and the total.

public class EventReporter : IDisposable
Inheritance
EventReporter
Implements
Inherited Members
Extension Methods

Remarks

With the log at Debug or lower, every event reports at once. A report goes at Information, with the scope's data.

Constructors

EventReporter(string, EventId, LogScope?, TimeSpan?)

Initializes a new instance of the EventReporter class, which starts its report job.

public EventReporter(string message, EventId eventId = default, LogScope? logScope = null, TimeSpan? period = null)

Parameters

message string

The message each report starts with.

eventId EventId

The reports' event ID.

logScope LogScope

The scope whose data each report carries, or null for none.

period TimeSpan?

How often to report, or null for DefaultInterval.

Properties

LastReportEventCount

Gets TotalEventCount as of the last report.

public int LastReportEventCount { get; }

Property Value

int

LastReportEventTime

Gets when the last report was made, in UTC; when the reporter was made, until then.

public DateTime LastReportEventTime { get; }

Property Value

DateTime

LogScope

Gets or sets the scope whose data each report carries.

public LogScope LogScope { get; set; }

Property Value

LogScope

TotalEventCount

Gets the number of events since the reporter was made.

public int TotalEventCount { get; }

Property Value

int

Methods

Dispose()

Reports what is left and stops the report job. Calling it again does nothing.

public void Dispose()

Raise()

Counts an event.

public bool Raise()

Returns

bool

true for the first event since the last report, so a caller can log its details beside the counts; otherwise, false.

Exceptions

ObjectDisposedException

The reporter is disposed.

Report()

Writes a report; called under the reporter's lock, only when there are events to report.

protected virtual void Report()