英文:
How do I log exceptions from a Routing Slip Activity within MassTransit?
问题
我们有一个Routing slip活动,出现了异常,但是当发生错误时,日志中没有记录任何信息。
我知道我们可以监听RoutingSlipFaulted
消息并检查异常,但我们也希望它能够在日志中显示,并且可能也显示在OTL数据中。
是否有一种方法可以将某些内容添加到管道中,以便活动能够捕获错误并像正常的消费者一样将其记录下来?
以下是运行出错的活动的日志:
16:31:32.516-D 创建发送传输: loopback://localhost/activity3_execute
16:31:32.518-D 发送 loopback://localhost/activity3_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip
16:31:32.518-D 接收 loopback://localhost/Activity2_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip Activity2(00:00:00.5259605)
16:31:32.523-D 执行活动: dc340000-5ece-a04a-d752-08db5d351d92 (Activity3, loopback://localhost/Activity3_execute)
完成活动 3
16:31:33.091-D 创建发送传输: loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipActivityFaulted
16:31:33.096-D 发送 loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipActivityFaulted dc340000-5ece-a04a-0382-08db5d351e97 MassTransit.Courier.Contracts.RoutingSlipActivityFaulted
16:31:33.097-D 创建发送传输: loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipFaulted
16:31:33.102-D 发送 loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipFaulted dc340000-5ece-a04a-ffe3-08db5d351e97 MassTransit.Courier.Contracts.RoutingSlipFaulted
16:31:33.103-D 接收 loopback://localhost/Activity3_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip Activity3(00:00:00.5843245)
英文:
We've got a Routing slip activity which is throwing an exception, however, nothing is written to the logs when this errors.
I know we can listen to the RoutingSlipFaulted
message and inspect the Exception, however, we'd also like it to be in the logs and maybe in the OTL data too.
Is there a way to stick something in to the pipeline for the activities to capture the error and log it like the normal consumers do?
Below is the log of running an activity that faulted.
16:31:32.516-D Create send transport: loopback://localhost/activity3_execute
16:31:32.518-D SEND loopback://localhost/activity3_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip
16:31:32.518-D RECEIVE loopback://localhost/Activity2_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip Activity2(00:00:00.5259605)
16:31:32.523-D Execute Activity: dc340000-5ece-a04a-d752-08db5d351d92 (Activity3, loopback://localhost/Activity3_execute)
Done Activity 3
16:31:33.091-D Create send transport: loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipActivityFaulted
16:31:33.096-D SEND loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipActivityFaulted dc340000-5ece-a04a-0382-08db5d351e97 MassTransit.Courier.Contracts.RoutingSlipActivityFaulted
16:31:33.097-D Create send transport: loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipFaulted
16:31:33.102-D SEND loopback://localhost/urn:message:MassTransit.Courier.Contracts:RoutingSlipFaulted dc340000-5ece-a04a-ffe3-08db5d351e97 MassTransit.Courier.Contracts.RoutingSlipFaulted
16:31:33.103-D RECEIVE loopback://localhost/Activity3_execute dc340000-5ece-a04a-f20d-08db5d351d93 MassTransit.Courier.Contracts.RoutingSlip Activity3(00:00:00.5843245)
答案1
得分: 1
故障的路由滑动活动与消费者异常处理方式不同,因此不会被记录为错误,因为路由滑动补偿可能会期望它们。而且你说得对,它们也没有被记录。
关于是否将这个功能添加进来,我没有明确的想法,因为对于习惯于现有(不记录的)行为的人来说,可能会产生很多噪音。
如果你在ExecuteContext<T>
上创建了一个筛选器并将其添加,你就可以自己记录异常。
实际上,我只是要添加这个功能,以便异常能够一致地被记录。
英文:
Faulted routing slip activities are handled different that consumer exceptions, and as such are not logged as errors since the routing slip compensation may expect them. And you're right, they are not logged either.
No real thoughts on whether this would be a useful addition, or create a bunch of noise for those used to the existing (not-logged) behavior.
If you created a filter on ExecuteContext<T>
and added it, you would be able to log exceptions yourself.
> Actually, I'm just going to add this so that the exceptions are logged consistently.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论