我使用 HttpLogging 来记录发送到我的端点的请求。我想记录整个请求。我在 Program.cs 中设置 HttpLogging
builder.Services.AddHttpLogging(logging =>
{
logging.LoggingFields = HttpLoggingFields.All;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpLogging();
Run Code Online (Sandbox Code Playgroud)
并更改 appsettings.Development.json 中的日志记录级别
"Microsoft.AspNetCore": "Information"
Run Code Online (Sandbox Code Playgroud)
然后,当我从 Postman 或 cURL 发送请求时,我可以看到所有需要的信息,但 RequestBody始终为空(靠近日志末尾)
info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[1]
Request:
Protocol: HTTP/1.1
Method: POST
Scheme: https
PathBase:
Path: /WeatherForecast
Accept: */*
Connection: keep-alive
Host: localhost:7269
User-Agent: PostmanRuntime/7.29.0
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Content-Length: 60
Postman-Token: [Redacted]
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'WebApplication1.Controllers.WeatherForecastController.Post (WebApplication1)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = …Run Code Online (Sandbox Code Playgroud)