MassTransit Mediator消费者异常未被日志记录的解决方法
根因说明
你观察到的MassTransit Mediator消费异常仅输出R-FAULT标记、无异常详情的问题,和MassTransit Mediator本身的配置逻辑无关,问题来源于项目依赖的aws-logging-dotnet包的默认行为:该包默认关闭了异常信息的输出开关,即使MassTransit已经将完整异常对象上报到日志上下文,也不会被序列化到最终日志中。
修复方案
修改日志配置,将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" } }
配置生效后重启服务,消费者抛出异常时,日志会自动输出完整的异常消息、堆栈轨迹等详情。
内容的提问来源于stack exchange,提问作者Kevin Smith
相关产品推荐
相关产品推荐

