Class InMemoryLogger

Namespace
Wolfgang.Extensions.Logging.InMemoryLogger
Assembly
Wolfgang.Extensions.Logging.InMemoryLogger.dll

An implementation of ILogger that logs messages to an in-memory collection.

[SuppressMessage("Style", "MA0049:Type name should not match containing namespace", Justification = "The package, namespace, and type intentionally share a name; the namespace is named after the project's primary type.")]
public class InMemoryLogger : ILogger
Inheritance
InMemoryLogger
Implements
Inherited Members

Constructors

InMemoryLogger(string, LogLevel, int)

Initializes a new instance of the InMemoryLogger class.

public InMemoryLogger(string category, LogLevel minLogLevel = LogLevel.Trace, int capacity = 16)

Parameters

category string

The category name for messages produced by the logger.

minLogLevel LogLevel

The minimum log level to log.

capacity int

The initial capacity of the log entries collection.

Exceptions

ArgumentNullException

Thrown when category is null.

ArgumentOutOfRangeException

Thrown when capacity is less than 1.

Properties

Capacity

The capacity of the internal log entries collection.

public int Capacity { get; }

Property Value

int

Category

Gets the category name for this logger.

public string Category { get; }

Property Value

string

LogEntries

Returns a readonly list of log entries that have been logged.

public IReadOnlyList<LogEntry<object>> LogEntries { get; }

Property Value

IReadOnlyList<LogEntry<object>>

MinimumLogLevel

Gets the minimum LogLevel for this instance.

public LogLevel MinimumLogLevel { get; }

Property Value

LogLevel

Scopes

Gets the currently active scopes as an array, from outermost to innermost.

public object[] Scopes { get; }

Property Value

object[]

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

A disposable object that ends the logical operation scope on dispose.

Type Parameters

TState

The type of the state.

IsEnabled(LogLevel)

Gets a value indicating if the specified log level is enabled.

public bool IsEnabled(LogLevel logLevel)

Parameters

logLevel LogLevel

The log level to check.

Returns

bool

true if the log level is enabled; otherwise, false.

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

Logs the specified data.

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

Parameters

logLevel LogLevel

The log level.

eventId EventId

The event ID associated with the log entry.

state TState

The state associated with the log entry.

exception Exception

The exception associated with the log entry, if any.

formatter Func<TState, Exception, string>

A function to create a string message from the state and exception.

Type Parameters

TState

The type of the state object.