Skip to main content

NotificationLoggingBehavior

Namespace: RA.Utilities.Dispatcher.Behaviors

NotificationLoggingBehavior<TNotification> is a notification behavior that logs each notification handler invocation at start and finish.

📦 Type Definition​

public class NotificationLoggingBehavior<TNotification> : INotificationBehavior<TNotification>
where TNotification : INotification
{
public NotificationLoggingBehavior(ILogger<NotificationLoggingBehavior<TNotification>> logger);
}

🎯 What It Logs​

EventLevelMessage
Handler invokedInformation[Notification Logging] Start. Notification: {@Notification}
SuccessInformation[Notification Logging] Finished. Notification: {@Notification}
Failed resultWarning[Notification Logging] Failed. Notification: {@Notification} (with the failure exception)

The behavior wraps next() for a single handler — each notification handler gets its own logging wrap.

🚀 Usage​

builder.Services
.AddNotification<OrderPlaced>()
.AddDecoration<NotificationLoggingBehavior<OrderPlaced>>();

Because the behavior is generic, the auto-registration generator reports DSAG010 and skips it — register it explicitly with AddDecoration, as above. Behaviors compose in registration order, outermost first — for the logging to see retries, register it inside the retry behavior:

builder.Services
.AddNotification<OrderPlaced>()
.AddDecoration<NotificationRetryBehavior<OrderPlaced>>() // outermost
.AddDecoration<NotificationLoggingBehavior<OrderPlaced>>(); // innermost

// For each handler: Retry → Logging → Handler