Class RamLogger
RAM-based logger essential implementation. Note that this does not honor scopes, but it is thread-safe.
public class RamLogger : ILogger
- Inheritance
-
RamLogger
- Implements
- Inherited Members
Remarks
Usage:
services.AddSingleton<ILogger>(
new RamLogger(LogLevel.Information));
Constructors
RamLogger(LogLevel)
Initializes a new instance of the RamLogger class.
public RamLogger(LogLevel minLevel = LogLevel.Information)
Parameters
minLevel
LogLevelThe minimum level.
Methods
BeginScope<TState>(TState)
Begins a logical operation scope.
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
Parameters
state
TStateThe 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.
Clear()
Clears all the entries collected in this logger.
public void Clear()
GetEntries()
Gets the entries clearing the log.
public IList<string> GetEntries()
Returns
IsEnabled(LogLevel)
Checks if the given logLevel
is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevel
LogLevelLevel 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
LogLevelEntry will be written on this level.
eventId
EventIdId of the event.
state
TStateThe entry to be written. Can be also an object.
exception
ExceptionThe exception related to this entry.
formatter
Func<TState, Exception, string>Function to create a string message of the
state
andexception
.
Type Parameters
TState
The type of the object to be written.