private async Task DispatchToSubscriberAsync( IDomainEvent domainEvent, ISubscribe subscriber, SubscriberInformation subscriberInformation, bool swallowException, CancellationToken cancellationToken) { _log.Verbose(() => $"Calling HandleAsync on handler '{subscriber.GetType().PrettyPrint()}' " + $"for aggregate event '{domainEvent.EventType.PrettyPrint()}'"); await _dispatchToSubscriberResilienceStrategy.BeforeHandleEventAsync( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); try { await subscriberInformation.HandleMethod( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); await _dispatchToSubscriberResilienceStrategy.HandleEventSucceededAsync( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); } catch (Exception e) when(swallowException) { _log.Error(e, $"Subscriber '{subscriberInformation.SubscriberType.PrettyPrint()}' threw " + $"'{e.GetType().PrettyPrint()}' while handling '{domainEvent.EventType.PrettyPrint()}': {e.Message}"); await _dispatchToSubscriberResilienceStrategy.HandleEventFailedAsync( subscriber, domainEvent, e, true, cancellationToken) .ConfigureAwait(false); } catch (Exception e) when(!swallowException) { await _dispatchToSubscriberResilienceStrategy.HandleEventFailedAsync( subscriber, domainEvent, e, false, cancellationToken) .ConfigureAwait(false); throw; } }
private async Task DispatchToSubscriberAsync( IDomainEvent domainEvent, ISubscribe subscriber, SubscriberInformation subscriberInformation, bool swallowException, CancellationToken cancellationToken) { _logger.LogTrace("Calling HandleAsync on handler {SubscriberType} for aggregate event {EventType}", subscriber.GetType().PrettyPrint(), domainEvent.EventType.PrettyPrint()); await _dispatchToSubscriberResilienceStrategy.BeforeHandleEventAsync( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); try { await subscriberInformation.HandleMethod( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); await _dispatchToSubscriberResilienceStrategy.HandleEventSucceededAsync( subscriber, domainEvent, cancellationToken) .ConfigureAwait(false); } catch (Exception e) when(swallowException) { _logger.LogError( e, "Subscriber {SubscriberType} threw {ExceptionType} while handling {EventType}: {ExceptionMessage}", subscriberInformation.SubscriberType.PrettyPrint(), e.GetType().PrettyPrint(), domainEvent.EventType.PrettyPrint(), e.Message); await _dispatchToSubscriberResilienceStrategy.HandleEventFailedAsync( subscriber, domainEvent, e, true, cancellationToken) .ConfigureAwait(false); } catch (Exception e) when(!swallowException) { await _dispatchToSubscriberResilienceStrategy.HandleEventFailedAsync( subscriber, domainEvent, e, false, cancellationToken) .ConfigureAwait(false); throw; } }