dotnet / dotnet/AspNetCore.Docs

Path doesn't get logged on Response or ResponseBody

Open
#25,712 1 comment 0 reactions 0 assignees View on GitHub
doc-enhancement re-Aditya Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

The documentation doesn't seem to match what the Http logger actually does.
It states:

_"By default, HTTP Logging logs common properties such as path, status-code, and headers for requests and responses. "_

But, when I put a POST request through, we get 4x log entries:

```
1. Request:
Protocol: HTTP/1.1
Method: POST
Scheme: http
PathBase:
Path: /example/demo
Host: localhost:19032
User-Agent: Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.19044; en-GB) PowerShell/7.1.4
Content-Type: application/json
Content-Length: 43

2. RequestBody: {
"message": "Mr. Watson, come here."
}

3. Response:
StatusCode: 200
Content-Type: application/json; charset=utf-8

4. ResponseBody: {
"message": "Your message was: Mr. Watson, come here.",
}
```

Only the first request item has the path on it - and there seems to be no way to correlate this to RequestBody / Response / ResponseBody other than timing (or luck).

Using a custom ILogger I can see that BeginScope is called 4 times too, so there isn't a way to link the log entries together using this.

Is the documentation inaccurate then, because it doesn't log the path on response?

Ideally there should be some way to correlate the logs together, not sure how this would work.

---
#### Document details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 7c772b2a-5d37-84af-624c-9022efe0758b
* Version Independent ID: b39594cc-9d1c-611c-e3e7-8755d74253a6
* Content: [HTTP Logging in .NET Core and ASP.NET Core](https://docs.microsoft.com/en-gb/aspnet/core/fundamentals/http-logging/?view=aspnetcore-6.0)
* Content Source: [aspnetcore/fundamentals/http-logging/index.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/http-logging/index.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-fundamentals**
* GitHub Login: @jkotalik
* Microsoft Alias: **jukotali**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.