Class LoggingBehavior<TMessage, TResponse>
Pipeline behavior that logs command/query execution with duration and Result outcome. Logs at Information level for success, Warning level for failure.
public sealed class LoggingBehavior<TMessage, TResponse> : IPipelineBehavior<TMessage, TResponse> where TMessage : IMessage where TResponse : IResult
Type Parameters
TMessageThe message type.
TResponseThe response type, constrained to IResult.
- Inheritance
-
LoggingBehavior<TMessage, TResponse>
- Implements
-
IPipelineBehavior<TMessage, TResponse>
- Inherited Members
- Extension Methods
Constructors
LoggingBehavior(ILogger<LoggingBehavior<TMessage, TResponse>>, TrellisMediatorTelemetryOptions?)
Initializes a new instance of the LoggingBehavior<TMessage, TResponse> class.
public LoggingBehavior(ILogger<LoggingBehavior<TMessage, TResponse>> logger, TrellisMediatorTelemetryOptions? options = null)
Parameters
loggerILogger<LoggingBehavior<TMessage, TResponse>>The logger instance.
optionsTrellisMediatorTelemetryOptionsTelemetry redaction options resolved from DI. When
null(i.e. not registered) the safe-by-default options are used and Detail is redacted.
Methods
Handle(TMessage, MessageHandlerDelegate<TMessage, TResponse>, CancellationToken)
public ValueTask<TResponse> Handle(TMessage message, MessageHandlerDelegate<TMessage, TResponse> next, CancellationToken cancellationToken)
Parameters
messageTMessagenextMessageHandlerDelegate<TMessage, TResponse>cancellationTokenCancellationToken
Returns
- ValueTask<TResponse>