Skip to content

Commit dc77590

Browse files
committed
Add API Browser cross-links
1 parent f568987 commit dc77590

File tree

1 file changed

+32
-42
lines changed
  • aspnetcore/fundamentals/http-logging

1 file changed

+32
-42
lines changed

aspnetcore/fundamentals/http-logging/index.md

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ms.custom: mvc
88
ms.date: 10/25/2023
99
uid: fundamentals/http-logging/index
1010
---
11-
1211
# HTTP logging in ASP.NET Core
1312

1413
[!INCLUDE[](~/includes/not-latest-version.md)]
@@ -46,8 +45,8 @@ The empty lambda in the preceding example of calling `AddHttpLogging` adds the m
4645
Add the following line to the `appsettings.Development.json` file at the `"LogLevel": {` level so the HTTP logs are displayed:
4746

4847
```json
49-
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
50-
```
48+
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
49+
```
5150

5251
With the default configuration, a request and response is logged as a pair of messages similar to the following example:
5352

@@ -87,11 +86,11 @@ To configure global options for the HTTP logging middleware, call <xref:Microsof
8786
[!code-csharp[](~/fundamentals/http-logging/samples/8.x/Program.cs?name=snippet_Addservices)]
8887

8988
> [!NOTE]
90-
> 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`.
89+
> 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`.
9190
9291
### `LoggingFields`
9392

94-
[`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 <xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.RequestPropertiesAndHeaders> | <xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.ResponsePropertiesAndHeaders>.
93+
[`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 <xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.RequestPropertiesAndHeaders> | <xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.ResponsePropertiesAndHeaders>.
9594

9695
### `RequestHeaders` and `ResponseHeaders`
9796

@@ -132,7 +131,7 @@ For endpoint-specific configuration in minimal API apps, a <xref:Microsoft.AspNe
132131

133132
[!code-csharp[](~/fundamentals/http-logging/samples/8.x/Program.cs?name=snippet6)]
134133

135-
For endpoint-specific configuration in apps that use controllers, the [`[HttpLogging]`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) attribute is available. The attribute can also be used in minimal API apps, as shown in the following example:
134+
For endpoint-specific configuration in apps that use controllers, the [`[HttpLogging]` attribute](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) is available. The attribute can also be used in minimal API apps, as shown in the following example:
136135

137136
[!code-csharp[](~/fundamentals/http-logging/samples/8.x/Program.cs?name=snippet5)]
138137

@@ -145,13 +144,13 @@ For endpoint-specific configuration in apps that use controllers, the [`[HttpLog
145144
* Adjust how much of the request or response body is logged.
146145
* Add custom fields to the logs.
147146

148-
Register an `IHttpLoggingInterceptor` implementation by calling [`AddHttpLoggingInterceptor<T>`](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.
147+
Register an <xref:Microsoft.AspNetCore.HttpLogging.IHttpLoggingInterceptor> implementation by calling <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLoggingInterceptor%2A> in `Program.cs`. If multiple <xref:Microsoft.AspNetCore.HttpLogging.IHttpLoggingInterceptor> instances are registered, they're run in the order registered.
149148

150-
The following example shows how to register an `IHttpLoggingInterceptor` implementation:
149+
The following example shows how to register an <xref:Microsoft.AspNetCore.HttpLogging.IHttpLoggingInterceptor> implementation:
151150

152151
[!code-csharp[](~/fundamentals/http-logging/samples/8.x/Program.cs?name=snippet4&highlight=7)]
153152

154-
The following example is an `IHttpLoggingInterceptor` implementation that:
153+
The following example is an <xref:Microsoft.AspNetCore.HttpLogging.IHttpLoggingInterceptor> implementation that:
155154

156155
* Inspects the request method and disables logging for POST requests.
157156
* For non-POST requests:
@@ -160,7 +159,7 @@ The following example is an `IHttpLoggingInterceptor` implementation that:
160159

161160
[!code-csharp[](~/fundamentals/http-logging/samples/8.x/SampleHttpLoggingInterceptor.cs)]
162161

163-
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:
162+
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:
164163

165164
```output
166165
info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[1]
@@ -200,7 +199,7 @@ info: Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware[8]
200199
The following list shows the order of precedence for logging configuration:
201200

202201
1. Global configuration from <xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingOptions>, set by calling <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A>.
203-
1. Endpoint-specific configuration from the [`[HttpLogging]`](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) attribute or the <xref:Microsoft.AspNetCore.Builder.HttpLoggingEndpointConventionBuilderExtensions.WithHttpLogging%2A> extension method overrides global configuration.
202+
1. Endpoint-specific configuration from the [`[HttpLogging]` attribute](xref:Microsoft.AspNetCore.HttpLogging.HttpLoggingAttribute) or the <xref:Microsoft.AspNetCore.Builder.HttpLoggingEndpointConventionBuilderExtensions.WithHttpLogging%2A> extension method overrides global configuration.
204203
1. [`IHttpLoggingInterceptor`](#ihttplogginginterceptor) is called with the results and can further modify the configuration per request.
205204

206205
:::moniker-end
@@ -211,17 +210,18 @@ The following list shows the order of precedence for logging configuration:
211210

212211
## Redacting sensitive data
213212

214-
Http logging with redaction can be enabled by calling `AddHttpLoggingRedaction`<!-- Microsoft.Extensions.DependencyInjection.HttpLoggingServiceCollectionExtensions.AddHttpLoggingRedaction> -->:
213+
Http logging with redaction can be enabled by calling <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServiceCollectionExtensions.AddHttpLoggingRedaction%2A>:
215214

216215
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet7&highlight=9)]
217216

218217
For more information about .NET's data redaction library, see [Data redaction in .NET](/dotnet/core/extensions/data-redaction).
219218

220219
## Logging redaction options
221220

222-
To configure options for logging with redaction, call `AddHttpLoggingRedaction`<!-- Microsoft.Extensions.DependencyInjection.HttpLoggingServiceCollectionExtensions.AddHttpLoggingRedaction>--> in `Program.cs`, using the lambda to configure <!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions>--> `LoggingRedactionOptions`:
221+
To configure options for logging with redaction, call <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServiceCollectionExtensions.AddHttpLoggingRedaction%2A> in `Program.cs` using the lambda to configure <xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions>:
223222

224223
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/MyTaxonomyClassifications.cs)]
224+
225225
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=6)]
226226

227227
With the previous redaction configuration, the output is similar to the following:
@@ -242,66 +242,56 @@ info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
242242
Request finished HTTP/2 GET https://localhost:61361/ - 200 - text/plain;+charset=utf-8 105.5334ms
243243
```
244244

245-
***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 <!-- Microsoft.Extensions.Compliance.Redaction.ErasingRedactor> --> `Redaction.ErasingRedactor`.
245+
> [!NOTE]
246+
> 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 <xref:Microsoft.Extensions.Compliance.Redaction.ErasingRedactor?displayProperty=nameWithType>.
246247
247-
### RequestPathLoggingMode
248+
### `RequestPathLoggingMode`
248249

249-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestPathLoggingMode>-->
250-
`RequestPathLoggingMode` determines how the request path is logged, whether `Formatted` or `Structured`.
250+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestPathLoggingMode%2A> determines how the request path is logged, whether `Formatted` or `Structured`, set by <xref:Microsoft.AspNetCore.Diagnostics.Logging.IncomingPathLoggingMode>:
251251

252-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.IncomingPathLoggingMode.Formatted> -->
253-
* `Formatted` logs the request path without parameters.
254-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.IncomingPathLoggingMode.Structured> -->
255-
* `Structured` logs the request path with parameters included.
252+
* `Formatted`: Logs the request path without parameters.
253+
* `Structured`: Logs the request path with parameters included.
256254

257255
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=9)]
258256

259-
### RequestPathParameterRedactionMode
257+
### `RequestPathParameterRedactionMode`
260258

261-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestPathParameterRedactionMode> -->
262-
`RequestPathParameterRedactionMode` specifies how route parameters in the request path should be redacted, whether `Strict`, `Loose`, or `None`.
259+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestPathParameterRedactionMode%2A>
260+
specifies how route parameters in the request path should be redacted, whether `Strict`, `Loose`, or `None`, set by <xref:Microsoft.Extensions.Http.Diagnostics.HttpRouteParameterRedactionMode>:
263261

264-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.HttpRouteParameterRedactionMode.Strict>-->
265262
* `Strict`: Request route parameters are considered sensitive, require explicit annotation with a data classification, and are redacted by default.
266-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.HttpRouteParameterRedactionMode.Loose>-->
267263
* `Loose`: All parameters are considered as non-sensitive and included as-is by default.
268-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.HttpRouteParameterRedactionMode.None>-->
269264
* `None`: Route parameters aren't redacted regardless of the presence of data classification annotations.
270265

271266
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=8)]
272267

273-
### RequestHeadersDataClasses
268+
### `RequestHeadersDataClasses`
274269

275-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestHeadersDataClasses>-->
276-
`RequestHeadersDataClasses` maps request headers to their data classification, which determines how they are redacted:
270+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestHeadersDataClasses%2A> maps request headers to their data classification, which determines how they are redacted:
277271

278272
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=10)]
279273

280-
### ResponseHeadersDataClasses
274+
### `ResponseHeadersDataClasses`
281275

282-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.ResponseHeadersDataClasses>-->
283-
`ResponseHeadersDataClasses`, similar to <!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestHeadersDataClasses>--> `RequestHeadersDataClasses`, but for response headers:
276+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.ResponseHeadersDataClasses%2A>, similar to <xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RequestHeadersDataClasses%2A>`, but for response headers:
284277

285278
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=11)]
286279

287-
### RouteParameterDataClasses
280+
### `RouteParameterDataClasses`
288281

289-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RouteParameterDataClasses>-->
290-
`RouteParameterDataClasses` maps route parameters to their data classification:
282+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.RouteParameterDataClasses%2A> maps route parameters to their data classification:
291283

292284
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=12,13,14,15)]
293285

294-
### ExcludePathStartsWith
286+
### `ExcludePathStartsWith`
295287

296-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.ExcludePathStartsWith>-->
297-
`ExcludePathStartsWith` specifies paths that should be excluded from logging entirely:
288+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.ExcludePathStartsWith%2A> specifies paths that should be excluded from logging entirely:
298289

299290
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=16,17)]
300291

301-
### IncludeUnmatchedRoutes
292+
### `IncludeUnmatchedRoutes`
302293

303-
<!-- Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.IncludeUnmatchedRoutes>-->
304-
`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:
294+
<xref:Microsoft.AspNetCore.Diagnostics.Logging.LoggingRedactionOptions.IncludeUnmatchedRoutes%2A> 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:
305295

306296
[!code-csharp[](~/fundamentals/http-logging/samples/9.x/Program.cs?name=snippet_redactionOptions&highlight=18)]
307297

0 commit comments

Comments
 (0)