dotnet / dotnet/aspnetcore

Add a judgment condition in app.UseHttpLogging()

Open
#48,360 1 comment 1 reaction 0 assignees View on GitHub
area-middleware
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

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

I have a scenario like this, there are many endpoints in my project, I use `app.UseHttpLogging()` middleware to log request and response, It works very well. But I have a special endpoint, when this endpoint return 200, it will not log request/response information. when this endpoint return 400 or any other statuscode, It will log the request/response information.

### Describe the solution you'd like

I know I can custom middleware to achieve it, But is it possible that `app.UseHttpLogging()` will integrate this judgment condition in future versions? I also try :
```
app.UseWhen(
context => !(context.Request.Path.StartsWithSegments("/xxx")
&& context.Response.StatusCode == 200),
builder => builder.UseHttpLogging()
);
```
But when this endpoint return 400, it also will log anything.

### Additional context

_No response_

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.