Skip to content

Easy way to log request and response bodies #13217

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

Closed
Mikilll94 opened this issue Aug 17, 2019 · 1 comment
Closed

Easy way to log request and response bodies #13217

Mikilll94 opened this issue Aug 17, 2019 · 1 comment

Comments

@Mikilll94
Copy link

Is your feature request related to a problem? Please describe.

I am trying to build a logging mechanism in my app which logs every request and response. There are many tutorials on how to do this. I think the most popular is:

https://exceptionnotfound.net/using-middleware-to-log-requests-and-responses-in-asp-net-core/

Unfortunately, I think that logging request and response bodies is too complicated because both request body and response body are Streams instead of strings. Just look at this code in this article. To achieve just simple logging we have to write a lot of difficult code. This also causes other problems which are related to Streams, i.e. Large Object Heap.

Many of these problems are described below this article in comments.

Describe the solution you'd like

I'd like to have an easy way to log request and response bodies in ASP.NET Core.
Solutions:

  1. Request and response bodies should be strings instead of streams (don't know if this is possible)
  2. Give a user some method to get request and response body as a string.

Additional context

Almost every app needs some way to log events happening in it. Middleware in ASP.NET Core seems the best place to include logging. Unfortunately, there is no official or approved solution on how to perform logging request and responses in ASP.NET Core.

@davidfowl
Copy link
Member

Dupe of #3700

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants