Table of Contents

Class SyncLogger

Namespace
VpnHood.Net.Toolkit.Logging
Assembly
VpnHood.Net.Toolkit.dll

Provides a logger that lets one thread at a time into the logger behind it. A failure of its Log is written to the console instead of thrown; BeginScope and IsEnabled pass a failure on.

public class SyncLogger : ILogger
Inheritance
SyncLogger
Implements
Inherited Members

Constructors

SyncLogger(ILogger)

Provides a logger that lets one thread at a time into the logger behind it. A failure of its Log is written to the console instead of thrown; BeginScope and IsEnabled pass a failure on.

public SyncLogger(ILogger logger)

Parameters

logger ILogger

The logger behind it.

Methods

BeginScope<TState>(TState)

Begins a logical operation scope.

public IDisposable? BeginScope<TState>(TState state) where TState : notnull

Parameters

state TState

The identifier for the scope.

Returns

IDisposable

An IDisposable that ends the logical operation scope on dispose.

Type Parameters

TState

The type of the state to begin scope for.

Remarks

It asks the logger behind it, under the lock.

IsEnabled(LogLevel)

Checks if the given logLevel is enabled.

public bool IsEnabled(LogLevel logLevel)

Parameters

logLevel LogLevel

Level to be checked.

Returns

bool

true if enabled.

Remarks

It asks the logger behind it, under the lock.

Log<TState>(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)

Writes a log entry.

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)

Parameters

logLevel LogLevel

Entry will be written on this level.

eventId EventId

Id of the event.

state TState

The entry to be written. Can be also an object.

exception Exception

The exception related to this entry.

formatter Func<TState, Exception, string>

Function to create a string message of the state and exception.

Type Parameters

TState

The type of the object to be written.

Remarks

It writes to the logger behind it, under the lock; a failure goes to the console.