From 450f52e18aa5880b124a3a5155140486d3083621 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 6 May 2021 10:47:38 +0800 Subject: [PATCH] write log when message move to dead letter --- .../Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs index 26b8dd17ee..774973c649 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Confluent.Kafka; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -11,9 +13,12 @@ namespace Volo.Abp.EventBus.Kafka { public class KafkaEventErrorHandler : EventErrorHandlerBase, ISingletonDependency { + protected ILogger Logger { get; set; } + public KafkaEventErrorHandler( IOptions options) : base(options) { + Logger = NullLogger.Instance; } protected override async Task Retry(EventExecutionErrorContext context) @@ -34,6 +39,10 @@ namespace Volo.Abp.EventBus.Kafka protected override async Task MoveToDeadLetter(EventExecutionErrorContext context) { + Logger.LogException( + context.Exceptions.Count == 1 ? context.Exceptions.First() : new AggregateException(context.Exceptions), + LogLevel.Error); + await context.EventBus.As().PublishToDeadLetterAsync( context.EventType, context.EventData,