using Microsoft.Extensions.Logging; using StellaOps.Policy.Engine.ExceptionCache; namespace StellaOps.Policy.Engine.Events; /// /// Publishes exception lifecycle events and keeps local caches warm. /// public interface IExceptionEventPublisher { Task PublishAsync(ExceptionEvent exceptionEvent, CancellationToken cancellationToken = default); } internal sealed class LoggingExceptionEventPublisher : IExceptionEventPublisher { private readonly IExceptionEffectiveCache? _cache; private readonly ILogger _logger; public LoggingExceptionEventPublisher( IExceptionEffectiveCache? cache, ILogger logger) { _cache = cache; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public async Task PublishAsync(ExceptionEvent exceptionEvent, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(exceptionEvent); if (_cache is not null) { await _cache.HandleExceptionEventAsync(exceptionEvent, cancellationToken).ConfigureAwait(false); } _logger.LogInformation( "Published exception event {EventType} for exception {ExceptionId} tenant {TenantId}", exceptionEvent.EventType, exceptionEvent.ExceptionId, exceptionEvent.TenantId); } }