After using services.AddHttpLogging(), the ResponseBody cannot be passed to Serilog for file logging. #58380
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I reviewed the source code and found that adding "ResponseBody" to the logContext's "Parameters" occurs after the interceptor's "OnResponseAsync" method is executed. I want to access the "ResponseBody" within this method and add it to the diagnostic context for logging with Serilog, but I have found that this is currently not achievable.
I expect to add the "ResponseBody" to the diagnostic context in the red box area in the diagram, so that it can be provided to Serilog for file logging, like in the line diagnosticContext.Set("RequestBody", requestBody);
The log template content for Serilog is like this:
Expected Behavior
In the SampleHttpLoggingInterceptor's OnResponseAsync method, read the ResponseBody from the logContext's Parameters, and then add it to the diagnostic context using diagnosticContext.Set("RequestBody", requestBody); to provide it to Serilog for file logging.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
.net 8.0
Anything else?
No response