Table of Contents

Class NullLoggerWrapper<T>

Namespace
Arc4u.Diagnostics
Assembly
Arc4u.Diagnostics.dll

Helper class to unit test the Arc4u logging.

public class NullLoggerWrapper<T> : ILoggerWrapper<T>, ILogger<T>, ILogger, ILoggerCallerMember

Type Parameters

T

The category type of the logger.

Inheritance
NullLoggerWrapper<T>
Implements
Inherited Members
Extension Methods

Fields

Instance

Gets the shared instance.

public static readonly NullLoggerWrapper<T> Instance

Field Value

NullLoggerWrapper<T>

Properties

AdditionalFields

Gets the additional properties that are written with the next log entry of this logger.

public Dictionary<string, object?> AdditionalFields { get; }

Property Value

Dictionary<string, object>

Remarks

The properties are cleared once the entry is written.

IncludeStackTrace

Sets a value indicating whether the stack trace is added to the next log entry; reset once the entry is written.

public bool IncludeStackTrace { get; set; }

Property Value

bool

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.

CallerMemberName(string)

Sets the name of the calling member that is written in the MethodName property of the next log entries.

public void CallerMemberName(string caller)

Parameters

caller string

The name of the calling method or property.

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.

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.

SetContext(string, string, Type?)

Returns a logger that writes its entries with the category, the calling member and optionally the source context type given.

public ILoggerWrapper<T> SetContext(string category, string caller = "", Type? realType = null)

Parameters

category string

The message category, see MessageCategory.

caller string

The name of the calling member.

realType Type

The type to report as the source context instead of T, or null to keep T.

Returns

ILoggerWrapper<T>

The logger wrapper to use for the entry.

Remarks

The returned logger has its own additional fields, so a logger shared between callers (or threads) is never modified by an entry being prepared.