Class MessageProcessingLogger
Wraps an ILogger with the ability to change its minimum log level at runtime. Decorates log messages using IDynamicMessageProcessor.
public class MessageProcessingLogger : ILogger
- Inheritance
-
MessageProcessingLogger
- Implements
- Derived
- Inherited Members
Constructors
MessageProcessingLogger(ILogger, LoggerFilter, IEnumerable<IDynamicMessageProcessor>)
Initializes a new instance of the MessageProcessingLogger class.
public MessageProcessingLogger(ILogger innerLogger, LoggerFilter filter, IEnumerable<IDynamicMessageProcessor> messageProcessors)
Parameters
innerLogger
ILoggerThe ILogger to wrap.
filter
LoggerFilterThe filter, which determines whether logging is enabled.
messageProcessors
IEnumerable<IDynamicMessageProcessor>The message processors to decorate log messages with.
Properties
InnerLogger
protected ILogger InnerLogger { get; }
Property Value
MessageProcessors
protected IReadOnlyCollection<IDynamicMessageProcessor> MessageProcessors { get; }
Property Value
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.
ChangeFilter(LoggerFilter)
Changes the log level filter at runtime.
public void ChangeFilter(LoggerFilter filter)
Parameters
filter
LoggerFilterThe updated filter, which determines whether logging is enabled.
IsEnabled(LogLevel)
Checks if the given logLevel
is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevel
LogLevelLevel to be checked.
Returns
Log<TState>(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)
Writes a log entry.
public virtual 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.