未登录 MassTransit Mediator 的异常
Posted
技术标签:
【中文标题】未登录 MassTransit Mediator 的异常【英文标题】:Exception not logged in MassTransit Mediator 【发布时间】:2021-12-28 13:03:24 【问题描述】:我们已连接 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"
【问题讨论】:
【参考方案1】:这可能与您的日志格式化程序的配置方式有关。 MassTransit 使用容器中的ILoggerFactory
。
例如我刚刚运行的测试出现异常显示消息,包括调用堆栈:
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
【讨论】:
感谢您的回复,提示将我转发给答案,它是aws-logging-dotnet
记录器,它默认配置为忽略日志输出中的异常!以上是关于未登录 MassTransit Mediator 的异常的主要内容,如果未能解决你的问题,请参考以下文章