NotificationMetricsBehavior
Namespace: RA.Utilities.Dispatcher.Behaviors
NotificationMetricsBehavior<TNotification> is a notification behavior that measures how long each notification handler takes and warns on slow handlers.
📦 Type Definition
public class NotificationMetricsBehavior<TNotification> : INotificationBehavior<TNotification>
where TNotification : INotification
{
public NotificationMetricsBehavior(ILogger<NotificationMetricsBehavior<TNotification>> logger);
}
🎯 How It Works
- Logs a
Debug-level marker (MetricsBehavior..). - Starts a timestamp with
Stopwatch.GetTimestamp()— no per-callStopwatchallocation (the timestamp API is allocation-free). - Invokes
next(). - If the inner pipeline took over 500 ms, logs a
Warning:Long running notification: {NotificationName} ({ElapsedMilliseconds}ms).
The measured result is passed through unchanged.
🚀 Usage
builder.Services
.AddNotification<OrderPlaced>()
.AddDecoration<NotificationMetricsBehavior<OrderPlaced>>();
Because the behavior is generic, the auto-registration generator reports DSAG010 and skips it — register it explicitly with AddDecoration, as above.