MassTransit Mediator 中未记录异常

Exception not logged in MassTransit Mediator

我们已连接 MassTransit Mediator 以将消息分散到 MassTransit 消费者。但是,如果这些消费者中的任何一个抛出异常,则该异常不会记录到日志中。

这是一个日志示例:

timestamp,message
START RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045 Version: $LATEST
[Information] MassTransit: Configured endpoint mediator, Consumer: Consumers.ItemCreatedConsumer 
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-9b4a-08d9a9d0888d ItemCreatedCreated.ItemCreatedCreated Consumers.ItemCreatedConsumer(00:00:08.7985055) 
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-9b4a-08d9a9d0888d 00:00:09.2821019 
END RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045
REPORT RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045  Duration: 21587.46 ms   Billed Duration: 21884 ms   Memory Size: 128 MB Max Memory Used: 115 MB Init Duration: 295.66 ms    
START RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045 Version: $LATEST
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-b6cb-08d9a9d0b20c ItemCreatedCreated.ItemCreatedCreated Consumers.ItemCreatedConsumer(00:00:00.1224263) 
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-b6cb-08d9a9d0b20c 00:00:00.1229786 
END RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045
REPORT RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045  Duration: 342.72 ms Billed Duration: 343 ms Memory Size: 128 MB Max Memory Used: 115 MB 
START RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045 Version: $LATEST
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-abde-08d9a9d0f33b ItemCreatedCreated.ItemCreatedCreated Consumers.ItemCreatedConsumer(00:00:00.0203362) 
[Error] MassTransit: R-FAULT loopback://localhost/mediator 811d0000-6752-ae0c-abde-08d9a9d0f33b 00:00:00.0206781 
END RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045
REPORT RequestId: 59108169-9b40-47e8-be40-b4baa4bbb045  Duration: 93.75 ms  Billed Duration: 94 ms  Memory Size: 128 MB Max Memory Used: 115 MB 

如何配置 Masstransit Mediator 以将异常消息记录到控制台(我确定默认情况下 MassTransit+RabbitMQ 会发生这种情况?)

谢谢

修复更新:

所以不记录异常的问题来自 aws-logging-dotnet 包,默认情况下它不输出异常。

需要添加以下配置 IncludeException 变为 true:

"Logging": {
  "Region": "us-east-1",
  "LogGroup": "AspNetCore.WebSample",
  "IncludeLogLevel": true,
  "IncludeCategory": true,
  "IncludeNewline": true,
  "IncludeException": true,
  "IncludeEventId": false,
  "IncludeScopes": false,
  "LogLevel": {
    "Default": "Debug",
    "System": "Information",
    "Microsoft": "Information"
  }
}

这可能与您的日志格式化程序的配置方式有关。 MassT运行sit 使用容器中的 ILoggerFactory

比如我刚才的测试运行有异常显示消息,包括callstack:

20:20:36.813-E R-FAULT loopback://localhost/mediator dc3a0000-ebb8-e450-78f0-08d9aa3a01fb MassTransit.TestFramework.Messages.PingMessage MassTransit.MessageHandler<MassTransit.TestFramework.Messages.PingMessage>(00:00:00.0006972)

MassTransit.TestFramework.IntentionalTestException: No thank you!
   at MassTransit.Tests.Delivering_a_message_via_the_mediator.<>c.<Should_fault_at_the_send>b__3_2(ConsumeContext`1 context) in /Users/chris/Code/MassTransit/tests/MassTransit.Tests/Mediator_Specs.cs:line 87
   at MassTransit.Pipeline.Filters.HandlerMessageFilter`1.GreenPipes.IFilter<MassTransit.ConsumeContext<TMessage>>.Send(ConsumeContext`1 context, IPipe`1 next) in /Users/chris/Code/MassTransit/src/MassTransit/Pipeline/Filters/HandlerMessageFilter.cs:line 51