Class InMemoryLogger<T>
- Namespace
- Wolfgang.Extensions.Logging.InMemoryLogger
- Assembly
- Wolfgang.Extensions.Logging.InMemoryLogger.dll
An implementation of ILogger<TCategoryName> 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<T> : ILogger<T>, ILogger
Type Parameters
TThe type whose name is used for the logger category name.
- Inheritance
-
InMemoryLogger<T>
- Implements
-
ILogger<T>
- Inherited Members
Constructors
InMemoryLogger(LogLevel, int)
Initializes a new instance of the InMemoryLogger<T> class.
public InMemoryLogger(LogLevel minLogLevel = LogLevel.Trace, int capacity = 16)
Parameters
minLogLevelLogLevelThe minimum log level to log.
capacityintThe initial capacity of the log entries collection.
Exceptions
- ArgumentOutOfRangeException
Thrown when capacity is less than 1.
Properties
Capacity
The capacity of the internal log entries collection.
public int Capacity { 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
An IDisposable that ends the logical operation scope on dispose.
Type Parameters
TStateThe type of the state to begin scope for.
IsEnabled(LogLevel)
Checks if the given logLevel is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevelLogLevelLevel to be checked.
Returns
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
logLevelLogLevelEntry will be written on this level.
eventIdEventIdId of the event.
stateTStateThe entry to be written. Can be also an object.
exceptionExceptionThe exception related to this entry.
formatterFunc<TState, Exception, string>Function to create a string message of the
stateandexception.
Type Parameters
TStateThe type of the object to be written.