diff --git a/aspnetcore/fundamentals/http-logging/index.md b/aspnetcore/fundamentals/http-logging/index.md index 8010761b7331..add6d1f89903 100644 --- a/aspnetcore/fundamentals/http-logging/index.md +++ b/aspnetcore/fundamentals/http-logging/index.md @@ -8,7 +8,6 @@ ms.custom: mvc ms.date: 10/25/2023 uid: fundamentals/http-logging/index --- - # HTTP logging in ASP.NET Core [!INCLUDE[](~/includes/not-latest-version.md)] @@ -46,8 +45,8 @@ The empty lambda in the preceding example of calling `AddHttpLogging` adds the m Add the following line to the `appsettings.Development.json` file at the `"LogLevel": {` level so the HTTP logs are displayed: ```json - "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information" - ``` +"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information" +``` With the default configuration, a request and response is logged as a pair of messages similar to the following example: @@ -87,11 +86,11 @@ To configure global options for the HTTP logging middleware, call [!NOTE] -> In the preceding sample and following samples, `UseHttpLogging` is called after `UseStaticFiles`, so HTTP logging is not enabled for static files. To enable static file HTTP logging, call `UseHttpLogging` before `UseStaticFiles`. +> In the preceding sample and following samples, `UseHttpLogging` is called after `UseStaticFiles`, so HTTP logging isn't enabled for static files. To enable static file HTTP logging, call `UseHttpLogging` before `UseStaticFiles`. ### `LoggingFields` -[`HttpLoggingOptions.LoggingFields`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingOptions.LoggingFields) is an enum flag that configures specific parts of the request and response to log. ``HttpLoggingOptions.LoggingFields`` defaults to | . +[`HttpLoggingOptions.LoggingFields`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingOptions.LoggingFields) is an enum flag that configures specific parts of the request and response to log. `LoggingFields` defaults to | . ### `RequestHeaders` and `ResponseHeaders` @@ -132,7 +131,7 @@ For endpoint-specific configuration in minimal API apps, a `](xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLoggingInterceptor%60%601(Microsoft.Extensions.DependencyInjection.IServiceCollection)) in `Program.cs`. If multiple `IHttpLoggingInterceptor` instances are registered, they're run in the order registered. +Register an implementation by calling in `Program.cs`. If multiple instances are registered, they're run in the order registered. -The following example shows how to register an `IHttpLoggingInterceptor` implementation: +The following example shows how to register an implementation: [!code-csharp[](~/fundamentals/http-logging/samples/8.x/Program.cs?name=snippet4&highlight=7)] -The following example is an `IHttpLoggingInterceptor` implementation that: +The following example is an implementation that: * Inspects the request method and disables logging for POST requests. * For non-POST requests: @@ -160,7 +159,7 @@ The following example is an `IHttpLoggingInterceptor` implementation that: [!code-csharp[](~/fundamentals/http-logging/samples/8.x/SampleHttpLoggingInterceptor.cs)] -With this interceptor, a POST request doesn't generate any logs even if HTTP logging is configured to log `HttpLoggingFields.All`. A GET request generates logs similar to the following example: +With this interceptor, a POST request doesn't generate any logs even if HTTP logging is configured to log [`HttpLoggingFields.All`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingFields). A GET request generates logs similar to the following example: ```output info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[1] @@ -200,7 +199,7 @@ info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[8] The following list shows the order of precedence for logging configuration: 1. Global configuration from , set by calling . -1. Endpoint-specific configuration from the [`[HttpLogging]`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) attribute or the extension method overrides global configuration. +1. Endpoint-specific configuration from the [`[HttpLogging]` attribute](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) or the extension method overrides global configuration. 1. [`IHttpLoggingInterceptor`](#ihttplogginginterceptor) is called with the results and can further modify the configuration per request. :::moniker-end @@ -211,7 +210,7 @@ The following list shows the order of precedence for logging configuration: ## Redacting sensitive data -Http logging with redaction can be enabled by calling `AddHttpLoggingRedaction`: +Http logging with redaction can be enabled by calling : [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet7&highlight=9)] @@ -219,9 +218,10 @@ For more information about .NET's data redaction library, see [Data redaction in ## Logging redaction options -To configure options for logging with redaction, call `AddHttpLoggingRedaction` in `Program.cs`, using the lambda to configure `LoggingRedactionOptions`: +To configure options for logging with redaction, call in `Program.cs` using the lambda to configure : [!code-csharp[](~/fundamentals/http-logging/samples/9.x/MyTaxonomyClassifications.cs)] + [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=6)] With the previous redaction configuration, the output is similar to the following: @@ -242,66 +242,56 @@ info: Microsoft.AspNetCore.Hosting.Diagnostics[2] Request finished HTTP/2 GET https://localhost:61361/ - 200 - text/plain;+charset=utf-8 105.5334ms ``` -***Note:*** Request path `/home` isn't logged because it is included in `ExcludePathStartsWith` property. `http.request.header.accept` and `http.response.header.content-type` were redacted by `Redaction.ErasingRedactor`. +> [!NOTE] +> Request path `/home` isn't logged because it's included in the [`ExcludePathStartsWith` property](#excludepathstartswith). `http.request.header.accept` and `http.response.header.content-type` were redacted by . -### RequestPathLoggingMode +### `RequestPathLoggingMode` - -`RequestPathLoggingMode` determines how the request path is logged, whether `Formatted` or `Structured`. + determines how the request path is logged, whether `Formatted` or `Structured`, set by : - -* `Formatted` logs the request path without parameters. - -* `Structured` logs the request path with parameters included. +* `Formatted`: Logs the request path without parameters. +* `Structured`: Logs the request path with parameters included. [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=9)] -### RequestPathParameterRedactionMode +### `RequestPathParameterRedactionMode` - -`RequestPathParameterRedactionMode` specifies how route parameters in the request path should be redacted, whether `Strict`, `Loose`, or `None`. + +specifies how route parameters in the request path should be redacted, whether `Strict`, `Loose`, or `None`, set by : - * `Strict`: Request route parameters are considered sensitive, require explicit annotation with a data classification, and are redacted by default. - * `Loose`: All parameters are considered as non-sensitive and included as-is by default. - * `None`: Route parameters aren't redacted regardless of the presence of data classification annotations. [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=8)] -### RequestHeadersDataClasses +### `RequestHeadersDataClasses` - -`RequestHeadersDataClasses` maps request headers to their data classification, which determines how they are redacted: + maps request headers to their data classification, which determines how they are redacted: [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=10)] -### ResponseHeadersDataClasses +### `ResponseHeadersDataClasses` - -`ResponseHeadersDataClasses`, similar to `RequestHeadersDataClasses`, but for response headers: +, similar to `, but for response headers: [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=11)] -### RouteParameterDataClasses +### `RouteParameterDataClasses` - -`RouteParameterDataClasses` maps route parameters to their data classification: + maps route parameters to their data classification: [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=12,13,14,15)] -### ExcludePathStartsWith +### `ExcludePathStartsWith` - -`ExcludePathStartsWith` specifies paths that should be excluded from logging entirely: + specifies paths that should be excluded from logging entirely: [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=16,17)] -### IncludeUnmatchedRoutes +### `IncludeUnmatchedRoutes` - -`IncludeUnmatchedRoutes` allows reporting unmatched routes. If set to `true`, logs whole path of routes not identified by [Routing](xref:fundamentals/routing) instead of logging `Unknown` value for path attribute: + allows reporting unmatched routes. If set to `true`, logs whole path of routes not identified by [Routing](xref:fundamentals/routing) instead of logging `Unknown` value for path attribute: [!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=18)]