We've wired up MassTransit Mediator to fan out messages on to MassTransit consumers. However, if any of these consumers throws an exception then the exception is not logged to the logs.
Here's an example of the logs:
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
How do I configure Masstransit Mediator to log the exception message to the console (I'm sure this happends by default with MassTransit+RabbitMQ?)
Thanks
Update on Fix:
So the issue from not logging the exception came from the aws-logging-dotnet package, by default it doesn't output the exceptions.
the following config needs be added with IncludeException
turned to 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"
}
}
It's likely something with the way your log formatter is configured. MassTransit uses ILoggerFactory
from the container.
For example, the test I just ran with an exception shows the message, including 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