NotificationManager

Models & Types · AiDotNet.TrainingMonitoring.Notifications

Manages multiple notification services and provides unified notification delivery.

Implements: IDisposable

How It Works

For Beginners: The NotificationManager allows you to send notifications through multiple channels (email, Slack, etc.) at once. It supports:

  • Sending to all registered services
  • Filtering by severity (only send errors via email, info via Slack)
  • Buffering notifications to avoid spam
  • Background sending for non-blocking operation

Example usage:

Constructors

Constructor Summary
NotificationManager(bool enableBuffering, TimeSpan? flushInterval) Creates a new notification manager.

Properties

Property Summary
NotificationSeverity DefaultMinimumSeverity { get; set; } Gets the default minimum severity for all services.
TimeSpan BufferFlushInterval { get; set; } Gets the buffer flush interval.
bool BufferingEnabled { get; set; } Gets whether buffering is enabled.
int MaxBufferSize { get; set; } Gets the maximum buffer size before automatic flush.

Methods

Method Summary
Dictionary<string, bool> Send(TrainingNotification notification) Sends a notification synchronously.
IEnumerable<string> GetServiceNames() Gets all registered service names.
INotificationService GetService(string serviceName) Gets a registered service by name.
Task FlushAsync(CancellationToken cancellationToken) Flushes the notification buffer immediately.
Task<Dictionary<string, bool>> SendAsync(TrainingNotification notification, CancellationToken cancellationToken) Sends a notification to all applicable services.
Task<Dictionary<string, bool>> TestAllServicesAsync(CancellationToken cancellationToken) Tests all registered services.
bool AddService(INotificationService service) Adds a notification service.
bool IsTypeEnabled(NotificationType type) Checks if a notification type is enabled.
bool RemoveService(string serviceName) Removes a notification service.
void Dispose() Disposes the notification manager and all services.
void SendBackground(TrainingNotification notification) Sends notifications in the background (fire-and-forget).
void SetMinimumSeverity(string serviceName, NotificationSeverity severity) Sets the minimum severity for a specific service.
void SetTypeEnabled(NotificationType type, bool enabled) Enables or disables a notification type.