Closed Ricky-G closed 6 years ago
Hi @Ricky-G ,
We cannot enrich the logs with the repsponse body because at the moment the log is written, the body is not yet rendered.
I will add a second repo (serilog-aspnetcore-middleware) that will work differently. It will add a log at the end of each request with all the necessary information.
@trenoncourt I've written something like that, its a middleware that gets run at the start, but the response is always coming out as weird characters. Would be keen to take a look at your implementation of the middleware, did you manage to get the response body logging?
@Ricky-G ,
Here is the middleware repository: https://github.com/trenoncourt/serilog-aspnetcore-middleware
The response body seems to be well treated as you can see in the sample picture.
Right now the enricher captures the request in the property "body" which is the request body how about adding the response body as well? any thoughts?
context.Response.OnStarting(state => { var httpContext = (HttpContext)state; //something like the below capture and store the body // httpContext.Response.Body return Task.CompletedTask; }, context);