I have set the code below on the “startup.cs”.
builder.Services.AddHttpLogging(logging =>
{
logging.LoggingFields = HttpLoggingFields.RequestBody | HttpLoggingFields.ResponseBody;
logging.RequestBodyLogLimit = 4096;
logging.ResponseBodyLogLimit = 4096;
});
After call the api. The log will show as below:
2024-07-23 22:19:10.5235 INFO Request:
2024-07-23 22:19:10.7989 INFO RequestBody: {
"Name": "John"
}
2024-07-23 22:19:10.8397 INFO Response:
2024-07-23 22:19:10.9075 INFO ResponseBody: {"Message":"Hello, John"}
I only need log the request and response body.
How to filter the Request and Response?
And I also want combine the request and response body into single line log.
It seems have CombineLogs property to do this but this property didn’t exist net 6.
And for some reason I can’t upgrade to net 8.
Is it possible combine the log in net 6?