Table of Contents

Class TextLogger

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

Provides a logger that makes a line's text once, for the logger behind it: the time in UTC, the category, the level and the scopes, the event's name, the message and the exception; it hands that over as the message.

public sealed class TextLogger : ILogger
Inheritance
TextLogger
Implements
Inherited Members

Remarks

A line reads HH:mm:ss.ffff | category | Info | scope => scope | event | message: the time in UTC, the level's first four characters, the scopes separated by =>, the event's name without its number, and after the message Exception: and the exception's text. A single line has every line break written as \n; otherwise the entry ends with a line break.

Constructors

TextLogger(ILogger, bool, bool, bool, string?, bool)

Provides a logger that makes a line's text once, for the logger behind it: the time in UTC, the category, the level and the scopes, the event's name, the message and the exception; it hands that over as the message.

public TextLogger(ILogger logger, bool singleLine = true, bool includeTime = true, bool includeScopes = true, string? categoryName = null, bool includeLevel = true)

Parameters

logger ILogger

The logger behind it.

singleLine bool

true for one line per entry, its own line breaks written as \n, for a destination that keeps each line as an entry of its own.

includeTime bool

true to write the time; false where the destination stamps its lines itself.

includeScopes bool

true to write the scopes.

categoryName string

The category to write, or null for none.

includeLevel bool

true to write the level; false where the destination records it itself.

Remarks

A line reads HH:mm:ss.ffff | category | Info | scope => scope | event | message: the time in UTC, the level's first four characters, the scopes separated by =>, the event's name without its number, and after the message Exception: and the exception's text. A single line has every line break written as \n; otherwise the entry ends with a line break.

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

The scopes are its own, written into each line with includeScopes.

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.

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 the line's text to the logger behind it, when that one takes the level.