Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IHttpRequestFeature.Path in RequestLoggingMiddleware to log RequestPath #265

Merged
merged 18 commits into from Nov 12, 2021
Merged

Use IHttpRequestFeature.Path in RequestLoggingMiddleware to log RequestPath #265

merged 18 commits into from Nov 12, 2021

Conversation

jarronshih
Copy link
Contributor

@jarronshih jarronshih commented Sep 23, 2021

Why

See #232

RequestPath uses RawTarget which includes query data inside.

What

IHttpRequestFeature.Path could be a better choose.

To not break the existing behavior, we make a option RequestLoggingOptions.IncludeRawTargetPath with default value true.

Demo

Use sample.cs to test

# With options.IncludeRawTargetPath = false
2021-09-27 15:43:03.148 -07:00 [INF] Now listening on: https://localhost:5001
2021-09-27 15:43:03.181 -07:00 [INF] Now listening on: http://localhost:5000
2021-09-27 15:43:03.183 -07:00 [INF] Application started. Press Ctrl+C to shut down.
2021-09-27 15:43:03.185 -07:00 [INF] Hosting environment: Development
2021-09-27 15:43:03.187 -07:00 [INF] Content root path: C:\git\serilog-aspnetcore\samples\Sample
2021-09-27 15:43:03.942 -07:00 [INF] Hello, world!
2021-09-27 15:43:04.067 -07:00 [INF] HTTP GET / responded 200 in 183.3057 ms
2021-09-27 15:43:13.467 -07:00 [INF] HTTP GET /Index responded 404 in 0.4129 ms
2021-09-27 15:43:19.619 -07:00 [INF] HTTP GET /Index responded 404 in 0.0240 ms

# With options.IncludeRawTargetPath = true, which is default behavior
2021-09-27 15:43:35.651 -07:00 [INF] Now listening on: https://localhost:5001
2021-09-27 15:43:35.728 -07:00 [INF] Now listening on: http://localhost:5000
2021-09-27 15:43:35.745 -07:00 [INF] Application started. Press Ctrl+C to shut down.
2021-09-27 15:43:35.748 -07:00 [INF] Hosting environment: Development
2021-09-27 15:43:35.751 -07:00 [INF] Content root path: C:\git\serilog-aspnetcore\samples\Sample
2021-09-27 15:43:36.331 -07:00 [INF] Hello, world!
2021-09-27 15:43:36.496 -07:00 [INF] HTTP GET / responded 200 in 212.8998 ms
2021-09-27 15:43:42.311 -07:00 [INF] HTTP GET /Index?foo=bar responded 404 in 0.2009 ms

@@ -68,6 +68,11 @@ public class RequestLoggingOptions
/// </summary>
public ILogger Logger { get; set; }

/// <summary>
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Co-authored-by: Ivan Maximov <sungam3r@yandex.ru>
@nblumhardt
Copy link
Member

This looks good! One last thought - RawTargetPath is a bit opaque - it will be hard to guess what it means without consulting the docs. What about if we try IncludeQueryInPath?

@jarronshih
Copy link
Contributor Author

Thanks @nblumhardt ! I update the PR with the suggested name

@nblumhardt
Copy link
Member

Thanks @jarronshih! Sorry to send one last round of requests 😅 but I've had some more time to think about this, and came to the following conclusions:

  • The property should probably call it RequestPath, i.e. IncludeQueryInRequestPath, because Path may have other interpretations
  • We should bump the major version number, and make the default false

I think the XDOC for the property might also read more like: Include the full URL query string in the <c>RequestPath</c> property that is attached to request log events. The default is <c>false</c>.

What do you think? I'm also happy making these kinds of changes post-merge, if you are out of time for it. Thanks again!

@jarronshih
Copy link
Contributor Author

jarronshih commented Nov 11, 2021

Hi @nblumhardt thanks for another round of review. I am also on the side to change default to false. But I am not familiar with the version bumping process.
I am keeping the default to true to prevent breaking change. Feel free to change the value to false and bump the version as the following action.

I update the variable name and doc in the last commit.

@nblumhardt nblumhardt changed the base branch from main to dev November 12, 2021 05:41
@nblumhardt nblumhardt merged commit 8e91c9a into serilog:dev Nov 12, 2021
@nblumhardt
Copy link
Member

Awesome, thanks @jarronshih 👍

@nblumhardt nblumhardt mentioned this pull request Feb 2, 2022
nblumhardt added a commit that referenced this pull request Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants