From 0bedd97eceb974d4cd3e96bdc911f70e831d4ed0 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 15 Aug 2022 10:00:22 -0700 Subject: [PATCH 1/3] AdditionalRequestHeaders --- aspnetcore/fundamentals/w3c-logger/index.md | 2 +- .../w3c-logger/samples/7.x/Program.cs | 35 +++++++++++++++++++ .../samples/7.x/W3CLoggerSample.csproj | 8 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 aspnetcore/fundamentals/w3c-logger/samples/7.x/Program.cs create mode 100644 aspnetcore/fundamentals/w3c-logger/samples/7.x/W3CLoggerSample.csproj diff --git a/aspnetcore/fundamentals/w3c-logger/index.md b/aspnetcore/fundamentals/w3c-logger/index.md index 02857b8f20cf..c7a2a2327dc8 100644 --- a/aspnetcore/fundamentals/w3c-logger/index.md +++ b/aspnetcore/fundamentals/w3c-logger/index.md @@ -102,7 +102,7 @@ By default, W3CLogger logs common properties such as path, status-code, date, ti To configure the W3CLogger middleware, call in `Program.cs`: -:::code language="csharp" source="samples/6.x/Program.cs" id="snippet_AddW3CLogging" highlight="3"::: +:::code language="csharp" source="samples/7.x/Program.cs" id="snippet_AddW3CLogging" highlight="3"::: ### `LoggingFields` diff --git a/aspnetcore/fundamentals/w3c-logger/samples/7.x/Program.cs b/aspnetcore/fundamentals/w3c-logger/samples/7.x/Program.cs new file mode 100644 index 000000000000..27ca6fa089a6 --- /dev/null +++ b/aspnetcore/fundamentals/w3c-logger/samples/7.x/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.HttpLogging; +using Microsoft.Extensions.DependencyInjection; + +// +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddW3CLogging(logging => +{ + // Log all W3C fields + logging.LoggingFields = W3CLoggingFields.All; + + logging.AdditionalRequestHeaders.Add("x-forwarded-for"); + logging.AdditionalRequestHeaders.Add("x-client-ssl-protocol"); + logging.FileSizeLimit = 5 * 1024 * 1024; + logging.RetainedFileCountLimit = 2; + logging.FileName = "MyLogFile"; + logging.LogDirectory = @"C:\logs"; + logging.FlushInterval = TimeSpan.FromSeconds(2); +}); +// + +// +var app = builder.Build(); + +app.UseW3CLogging(); + +app.UseRouting(); +// + +app.MapGet("/", () => "Hello World!"); + +app.Run(); diff --git a/aspnetcore/fundamentals/w3c-logger/samples/7.x/W3CLoggerSample.csproj b/aspnetcore/fundamentals/w3c-logger/samples/7.x/W3CLoggerSample.csproj new file mode 100644 index 000000000000..9975b9fcf0e6 --- /dev/null +++ b/aspnetcore/fundamentals/w3c-logger/samples/7.x/W3CLoggerSample.csproj @@ -0,0 +1,8 @@ + + + + net7.0 + W3CLoggerSample + + + From eb6ade9052afbfa7ef9c3dc12c8684ba9450e325 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 15 Aug 2022 10:25:46 -0700 Subject: [PATCH 2/3] AdditionalRequestHeders --- aspnetcore/release-notes/aspnetcore-7.0.md | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/aspnetcore/release-notes/aspnetcore-7.0.md b/aspnetcore/release-notes/aspnetcore-7.0.md index 46708930f0eb..73836a08be67 100644 --- a/aspnetcore/release-notes/aspnetcore-7.0.md +++ b/aspnetcore/release-notes/aspnetcore-7.0.md @@ -4,7 +4,7 @@ author: rick-anderson description: Learn about the new features in ASP.NET Core 7.0. ms.author: riande ms.custom: mvc -ms.date: 08/09/2022 +ms.date: 08/15/2022 uid: aspnetcore-7 --- # What's new in ASP.NET Core 7.0 preview @@ -29,7 +29,7 @@ The [`IParsable.TryParse`](/dotnet/api/system.iparsable-1.tryparse#system ### Parameter binding with DI in API controllers -Parameter binding for API controller actions binds parameters through [dependency injection](xref:fundamentals/dependency-injection) when the type is configured as a service. This means it’s no longer required to explicitly apply the [`[FromServices]`](xref:Microsoft.AspNetCore.Mvc.FromServicesAttribute) attribute to a parameter. In the following code, both actions return the time: +Parameter binding for API controller actions binds parameters through [dependency injection](xref:fundamentals/dependency-injection) when the type is configured as a service. This means it's no longer required to explicitly apply the [`[FromServices]`](xref:Microsoft.AspNetCore.Mvc.FromServicesAttribute) attribute to a parameter. In the following code, both actions return the time: [!code-csharp[](~/release-notes/aspnetcore-7/samples/ApiController/Controllers/MyController.cs?name=snippet)] @@ -109,7 +109,7 @@ The following code shows the complete `Program.cs` file: Limitations when binding request body to `Stream` or `PipeReader`: * When reading data, the `Stream` is the same object as `HttpRequest.Body`. -* The request body isn’t buffered by default. After the body is read, it’s not rewindable. The stream can't be read multiple times. +* The request body isn't buffered by default. After the body is read, it's not rewindable. The stream can't be read multiple times. * The `Stream` and `PipeReader` aren't usable outside of the minimal action handler as the underlying buffers will be disposed or reused. ### New Results.Stream overloads @@ -122,7 +122,7 @@ For more information, see [Stream examples](xref:fundamentals/minimal-apis?view= ### Typed results for minimal APIs -In .NET 6, the interface was introduced to represent values returned from minimal APIs that don’t utilize the implicit support for JSON serializing the returned object to the HTTP response. The static [Results](/dotnet/api/microsoft.aspnetcore.http.results) class is used to create varying `IResult` objects that represent different types of responses. For example, setting the response status code or redirecting to another URL. The `IResult` implementing framework types returned from these methods were internal however, making it difficult to verify the specific `IResult` type being returned from methods in a unit test. +In .NET 6, the interface was introduced to represent values returned from minimal APIs that don't utilize the implicit support for JSON serializing the returned object to the HTTP response. The static [Results](/dotnet/api/microsoft.aspnetcore.http.results) class is used to create varying `IResult` objects that represent different types of responses. For example, setting the response status code or redirecting to another URL. The `IResult` implementing framework types returned from these methods were internal however, making it difficult to verify the specific `IResult` type being returned from methods in a unit test. In .NET 7 the types implementing `IResult` are public, allowing for type assertions when testing. For example: @@ -209,7 +209,7 @@ For more information, see [Shadow copying in IIS](xref:host-and-deploy/iis/advan The console output from dotnet watch has been improved to better align with the logging of ASP.NET Core and to stand out with 😮emojis😍. -Here’s an example of what the new output looks like: +Here's an example of what the new output looks like: ![output for dotnet watch](~/release-notes/aspnetcore-7/static/dnwatch.png) @@ -217,7 +217,7 @@ See [this GitHub pull request](https://github.com/dotnet/sdk/pull/23318) for mor ### Configure dotnet watch to always restart for rude edits -Rude edits are edits that can’t be hot reloaded. To configure dotnet watch to always restart without a prompt for rude edits, set the `DOTNET_WATCH_RESTART_ON_RUDE_EDIT` environment variable to `true`. +Rude edits are edits that can't be hot reloaded. To configure dotnet watch to always restart without a prompt for rude edits, set the `DOTNET_WATCH_RESTART_ON_RUDE_EDIT` environment variable to `true`. ### Developer exception page dark mode @@ -249,4 +249,18 @@ The Angular project template has been updated to Angular 14. The React project t ### Manage JSON Web Tokens in development with dotnet user-jwts -The new `dotnet user-jwts` command line tool can create and manage app specific local [JSON Web Tokens](https://jwt.io/introduction) (JWTs). For more information, see [Manage JSON Web Tokens in development with dotnet user-jwts](xref:security/authentication/jwt?view=aspnetcore-7.0&preserve-view=true). \ No newline at end of file +The new `dotnet user-jwts` command line tool can create and manage app specific local [JSON Web Tokens](https://jwt.io/introduction) (JWTs). For more information, see [Manage JSON Web Tokens in development with dotnet user-jwts](xref:security/authentication/jwt?view=aspnetcore-7.0&preserve-view=true). + +### Support for additional request headers in W3CLogger + +You can now specify additional request headers to log when using the W3C logger by calling `AdditionalRequestHeaders()` on : + +```csharp +services.AddW3CLogging(logging => +{ + logging.AdditionalRequestHeaders.Add("x-forwarded-for"); + logging.AdditionalRequestHeaders.Add("x-client-ssl-protocol"); +}); +``` + +For more information,see [W3CLogger options](xref:fundamentals/w3c-logger/index#w3clogger-options). From 7fbf9e2d9ecc4f42b7016e5bc1be16900e29e8b1 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 15 Aug 2022 10:45:09 -0700 Subject: [PATCH 3/3] fix link --- aspnetcore/release-notes/aspnetcore-7.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/release-notes/aspnetcore-7.0.md b/aspnetcore/release-notes/aspnetcore-7.0.md index 73836a08be67..e905192e7536 100644 --- a/aspnetcore/release-notes/aspnetcore-7.0.md +++ b/aspnetcore/release-notes/aspnetcore-7.0.md @@ -263,4 +263,4 @@ services.AddW3CLogging(logging => }); ``` -For more information,see [W3CLogger options](xref:fundamentals/w3c-logger/index#w3clogger-options). +For more information,see [W3CLogger options](xref:fundamentals/w3c-logger/index#w3clogger-options-1).