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
categorystringThe category name for messages produced by the logger.
minLogLevelLogLevelThe minimum log level to log.
capacityintThe initial capacity of the log entries collection.
Exceptions
- ArgumentNullException
Thrown when
categoryis 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
Category
Gets the category name for this logger.
public string Category { get; }
Property Value
LogEntries
Returns a readonly list of log entries that have been logged.
public IReadOnlyList<LogEntry<object>> LogEntries { get; }
Property Value
MinimumLogLevel
Gets the minimum LogLevel for this instance.
public LogLevel MinimumLogLevel { get; }
Property Value
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
stateTStateThe identifier for the scope.
Returns
- IDisposable
A disposable object that ends the logical operation scope on dispose.
Type Parameters
TStateThe type of the state.
IsEnabled(LogLevel)
Gets a value indicating if the specified log level is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevelLogLevelThe log level to check.
Returns
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
logLevelLogLevelThe log level.
eventIdEventIdThe event ID associated with the log entry.
stateTStateThe state associated with the log entry.
exceptionExceptionThe exception associated with the log entry, if any.
formatterFunc<TState, Exception, string>A function to create a string message from the state and exception.
Type Parameters
TStateThe type of the state object.