diff --git a/aspnetcore/fundamentals/w3c-logger/index.md b/aspnetcore/fundamentals/w3c-logger/index.md index f61bcdfc83be..29caaf807fa3 100644 --- a/aspnetcore/fundamentals/w3c-logger/index.md +++ b/aspnetcore/fundamentals/w3c-logger/index.md @@ -2,11 +2,9 @@ title: W3CLogger in .NET and ASP.NET Core description: Learn how to create server logs in the W3C standard format. monikerRange: '>= aspnetcore-6.0' -ms.date: 08/15/2022 -ms.reviewer: wigodbe +ms.date: 10/09/2026 uid: fundamentals/w3c-logger/index --- - # W3CLogger in ASP.NET Core [!INCLUDE[](~/includes/not-latest-version.md)] @@ -34,9 +32,22 @@ W3CLogger ***can reduce the performance of an app***. Consider the performance i ## Enable W3CLogger -Enable W3CLogger with , which adds the W3CLogger middleware: +Call to add the W3CLogger services to the dependency injection container: + +```csharp +builder.Services.AddW3CLogging(logging => +{ + // Set logging properties here +}); +``` + +Next, call to add the W3CLogger middleware to the request processing pipeline: + +```csharp +app.UseW3CLogging(); +``` -:::code language="csharp" source="samples/6.x/Program.cs" id="snippet_UseW3CLogging" highlight="3"::: +By default, log files are written to a `logs` directory in the app's content root directory (`./logs/`) with the file name prefix `w3clog-` (for example, `./logs/w3clog-20210929.0000.txt`). By default, W3CLogger logs common properties such as path, status-code, date, time, and protocol. All information about a single request/response pair is written to the same line. @@ -51,13 +62,18 @@ By default, W3CLogger logs common properties such as path, status-code, date, ti ## W3CLogger options -To configure the W3CLogger middleware, call in `Program.cs`: +To configure the W3CLogger middleware, call and configure in `Program.cs`: -:::code language="csharp" source="samples/6.x/Program.cs" id="snippet_AddW3CLogging" highlight="3"::: +:::code language="csharp" source="samples/6.x/Program.cs" id="snippet_AddW3CLogging" highlight="3-13"::: -### `LoggingFields` + supports the following properties: - is a bit flag enumeration that configures specific parts of the request and response to log, and other information about the connection. `LoggingFields` defaults to include all possible fields except `UserName` and `Cookie`. For a complete list of available fields, see . +* : The log file name prefix. Defaults to `w3clog-`. +* : Gets or sets a strictly positive value representing the maximum log size in bytes or null for no limit. Once the log is full, no more messages will be appended. Defaults to 10MB (10 * 1024 * 1024). +* : The period after which logs are flushed to disk. Defaults to 1 second. +* : The directory where log files are written. Defaults to `./logs/` relative to the app's content root directory. +* : The maximum number of retained log files. Defaults to 4. +* : A bit flag enumeration that configures specific parts of the request and response to log and other information about the connection. Defaults to include all possible fields except `UserName` and `Cookie`. For a complete list of available fields, see . ::: moniker-end @@ -84,9 +100,22 @@ W3CLogger ***can reduce the performance of an app***. Consider the performance i ## Enable W3CLogger -Enable W3CLogger with , which adds the W3CLogger middleware: +Call to add the W3CLogger services to the dependency injection container: + +```csharp +builder.Services.AddW3CLogging(logging => +{ + // Set logging properties here +}); +``` + +Next, call to add the W3CLogger middleware to the request processing pipeline: + +```csharp +app.UseW3CLogging(); +``` -:::code language="csharp" source="samples/6.x/Program.cs" id="snippet_UseW3CLogging" highlight="3"::: +By default, log files are written to a `logs` directory in the app's content root directory (`./logs/`) with the file name prefix `w3clog-` (for example, `./logs/w3clog-20210929.0000.txt`). By default, W3CLogger logs common properties such as path, status-code, date, time, and protocol. All information about a single request/response pair is written to the same line. @@ -101,12 +130,18 @@ By default, W3CLogger logs common properties such as path, status-code, date, ti ## W3CLogger options -To configure the W3CLogger middleware, call in `Program.cs`: +To configure the W3CLogger middleware, call and configure in `Program.cs`: -:::code language="csharp" source="samples/7.x/Program.cs" id="snippet_AddW3CLogging" highlight="3"::: +:::code language="csharp" source="samples/7.x/Program.cs" id="snippet_AddW3CLogging" highlight="3-15"::: -### `LoggingFields` + supports the following properties: - is a bit flag enumeration that configures specific parts of the request and response to log, and other information about the connection. `LoggingFields` defaults to include all possible fields except `UserName` and `Cookie`. For a complete list of available fields, see . +* : Additional request headers to include in the log file. +* : The log file name prefix. Defaults to `w3clog-`. +* : Gets or sets a strictly positive value representing the maximum log size in bytes or null for no limit. Once the log is full, no more messages will be appended. Defaults to 10MB (10 * 1024 * 1024). +* : The period after which logs are flushed to disk. Defaults to 1 second. +* : The directory where log files are written. Defaults to `./logs/` relative to the app's content root directory. +* : The maximum number of retained log files. Defaults to 4. +* : A bit flag enumeration that configures specific parts of the request and response to log and other information about the connection. Defaults to include all possible fields except `UserName` and `Cookie`. For a complete list of available fields, see . ::: moniker-end