-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Description
Background and Motivation
I need to log the body of every requests that are coming to the application, but I want to exclude some endpoints. For example I don't want to log the body of the login methods. I suggest adding metadata for enabling and disabling log for http logging middleware.
The new behavior would be like these: if endpoint has DisableLoggingAttribute the middleware would be skipped completely. when EnableLoggingAttribute is available the middleware use its LoggingFields to log the request/response and if there are no metadata available, it would use HttpLoggingOptions.LoggingFields.
Also should other HttpLoggingOptions properties be available in the metadata or is logging fields enough?
Proposed API
namespace Microsoft.AspNetCore.HttpLogging;
+ public class EnableLoggingAttribute : Attribute
+{
+ public EnableLoggingAttribute(HttpLoggingFields fields) { }
+ public HttpLoggingFields LoggingFields { get; }
+}
+ public class DisableLoggingAttribute : Attribute
+{
+}
namespace Microsoft.AspNetCore.Builder;
+public static class HttpLoggingEndpointConventionBuilderExtensions
+{
+ public static TBuilder EnableLogging<TBuilder>(this TBuilder builder, HttpLoggingFields loggingFields) where TBuilder : IEndpointConventionBuilder;
+ public static TBuilder DisableLogging<TBuilder>(this TBuilder builder) where TBuilder : IEndpointConventionBuilder;
+}Usage Examples
app.MapPost("/login", ... ).DisableLogging();
app.MapPost("/uploadFile", ... ).EnableLogging(HttpLoggingFields.RequestPropertiesAndHeaders);Alternative Designs
Risks
murad88, michal-zatloukal and ZJKung
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions