Skip to content

Commit 23d67d8

Browse files
Copilotgewarren
andcommitted
Add HTTP logging middleware breaking change documentation for .NET 8
Co-authored-by: gewarren <[email protected]>
1 parent 8288fd1 commit 23d67d8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "Breaking change: HTTP logging middleware requires AddHttpLogging"
3+
description: Learn about the breaking change in ASP.NET Core 8.0 where HTTP logging middleware now requires AddHttpLogging to be called on app startup.
4+
ms.date: 11/14/2023
5+
---
6+
# HTTP logging middleware requires AddHttpLogging
7+
8+
ASP.NET Core HTTP logging middleware has been updated with extra functionality. The middleware now requires services registered with <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A>.
9+
10+
## Version introduced
11+
12+
ASP.NET Core 8.0
13+
14+
## Previous behavior
15+
16+
Previously, HTTP logging could be used by calling only <xref:Microsoft.AspNetCore.Builder.HttpLoggingBuilderExtensions.UseHttpLogging%2A>:
17+
18+
```csharp
19+
var builder = WebApplication.CreateBuilder(args);
20+
21+
var app = builder.Build();
22+
app.UseHttpLogging();
23+
app.MapGet("/", () => "Hello World!");
24+
app.Run();
25+
```
26+
27+
## New behavior
28+
29+
If <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> is not called on app startup, ASP.NET Core throws an informative error:
30+
31+
> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`1[Microsoft.AspNetCore.HttpLogging.HttpLoggingInterceptorContext]' while attempting to activate 'Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware'.
32+
33+
## Type of breaking change
34+
35+
This change is a [behavioral change](../../categories.md#behavioral-change).
36+
37+
## Reason for change
38+
39+
Additional features were added to the HttpLogging middleware which are registered (and configurable) via the <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> method.
40+
41+
## Recommended action
42+
43+
Ensure that <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> is called at application startup.
44+
45+
For example:
46+
47+
```csharp
48+
var builder = WebApplication.CreateBuilder(args);
49+
builder.Services.AddHttpLogging();
50+
51+
var app = builder.Build();
52+
app.UseHttpLogging();
53+
app.MapGet("/", () => "Hello World!");
54+
app.Run();
55+
```
56+
57+
## Affected APIs
58+
59+
- <xref:Microsoft.AspNetCore.Builder.HttpLoggingBuilderExtensions.UseHttpLogging%2A?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ items:
224224
href: aspnet-core/8.0/concurrencylimitermiddleware-obsolete.md
225225
- name: Custom converters for serialization removed
226226
href: aspnet-core/8.0/problemdetails-custom-converters.md
227+
- name: HTTP logging middleware requires AddHttpLogging
228+
href: aspnet-core/8.0/httpLogging-addhttplogging-requirement.md
227229
- name: ISystemClock is obsolete
228230
href: aspnet-core/8.0/isystemclock-obsolete.md
229231
- name: "Minimal APIs: IFormFile parameters require anti-forgery checks"

0 commit comments

Comments
 (0)