Class InMemoryLoggerProvider

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

An ILoggerProvider that creates InMemoryLogger instances and provides access to all log entries across all loggers.

public sealed class InMemoryLoggerProvider : ILoggerProvider, IDisposable
Inheritance
InMemoryLoggerProvider
Implements
Inherited Members

Constructors

InMemoryLoggerProvider(LogLevel)

Initializes a new instance of the InMemoryLoggerProvider class.

public InMemoryLoggerProvider(LogLevel minLogLevel = LogLevel.Trace)

Parameters

minLogLevel LogLevel

The minimum log level for all loggers created by this provider.

Properties

LogEntries

Returns all log entries from all loggers created by this provider. Entries are grouped by logger category; ordering across categories is not guaranteed.

[SuppressMessage("Major Code Smell", "S2365:Properties should not make collection or array copies", Justification = "This is a test-helper property whose entire purpose is to return a snapshot view; the copy semantics are intentional and idiomatic for assertion code.")]
public IReadOnlyList<LogEntry<object>> LogEntries { get; }

Property Value

IReadOnlyList<LogEntry<object>>

Remarks

Each access materializes a snapshot of the entries across all loggers; the cost is O(n) in the total entry count. Test code typically reads this once per assertion.

Loggers

Returns all logger instances created by this provider.

[SuppressMessage("Major Code Smell", "S2365:Properties should not make collection or array copies", Justification = "This is a test-helper property whose entire purpose is to return a snapshot view; the copy semantics are intentional and idiomatic for assertion code.")]
public IReadOnlyDictionary<string, InMemoryLogger> Loggers { get; }

Property Value

IReadOnlyDictionary<string, InMemoryLogger>

Remarks

Each access materializes a snapshot copy of the underlying logger map; cost is O(n) in the number of distinct categories logged through this provider.

Methods

CreateLogger(string)

Creates a new InMemoryLogger with the given category name.

public ILogger CreateLogger(string categoryName)

Parameters

categoryName string

The category name for messages produced by the logger.

Returns

ILogger

An ILogger instance.

Exceptions

ArgumentNullException

Thrown when categoryName is null.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()