Table of Contents

Class LoggingBehavior<TMessage, TResponse>

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

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

TMessage

The message type.

TResponse

The 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

logger ILogger<LoggingBehavior<TMessage, TResponse>>

The logger instance.

options TrellisMediatorTelemetryOptions

Telemetry 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

message TMessage
next MessageHandlerDelegate<TMessage, TResponse>
cancellationToken CancellationToken

Returns

ValueTask<TResponse>