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. The per-message start entry is logged at Debug; the matching end entry is at Debug on success, Information for expected caller/domain failures (validation, authentication, authorization, not-found, conflict, rate-limited, invariant-violation, gone, and aggregates whose inner errors are all expected), and Warning for unexpected, dependency, or opaque transport failures. Cross-cutting per-message observability noise belongs at Debug, not Information; consumers who want per-call timing in production raise the level via "Trellis.Mediator": "Debug" in their logging configuration.

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. Under AddTrellisBehaviors(IServiceCollection) the singleton is always registered, so this argument is non-null in production. The optional-null fallback exists only for consumers that instantiate the behavior outside of DI (custom test fixtures); when null, the safe-by-default options are used and Detail is redacted.

Exceptions

ArgumentNullException

Thrown when logger is null.

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>