You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
9
@@ -13,20 +13,11 @@ ASP.NET Core 8.0
13
13
14
14
## Previous behavior
15
15
16
-
Previously, HTTP logging could be used by calling only <xref:Microsoft.AspNetCore.Builder.HttpLoggingBuilderExtensions.UseHttpLogging%2A>:
17
-
18
-
```csharp
19
-
varbuilder=WebApplication.CreateBuilder(args);
20
-
21
-
varapp=builder.Build();
22
-
app.UseHttpLogging();
23
-
app.MapGet("/", () =>"Hello World!");
24
-
app.Run();
25
-
```
16
+
Previously, you could call just `app.UseHttpLogging();` to activate HTTP logging.
26
17
27
18
## New behavior
28
19
29
-
If <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> is not called on app startup, ASP.NET Core throws an informative error:
20
+
Starting in .NET 8, if you don't also call <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A>, an error is raised:
30
21
31
22
> 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
23
@@ -36,24 +27,12 @@ This change is a [behavioral change](../../categories.md#behavioral-change).
36
27
37
28
## Reason for change
38
29
39
-
Additional features were added to the HttpLogging middleware which are registered (and configurable) via the <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> method.
30
+
Additional features were added to the HttpLogging middleware that are registered (and configurable) via the <xref:Microsoft.AspNetCore.Telemetry.HttpLoggingServiceExtensions.AddHttpLogging*> method.
40
31
41
32
## Recommended action
42
33
43
-
Ensure that <xref:Microsoft.Extensions.DependencyInjection.HttpLoggingServicesExtensions.AddHttpLogging%2A> is called at application startup.
44
-
45
-
For example:
46
-
47
-
```csharp
48
-
varbuilder=WebApplication.CreateBuilder(args);
49
-
builder.Services.AddHttpLogging();
50
-
51
-
varapp=builder.Build();
52
-
app.UseHttpLogging();
53
-
app.MapGet("/", () =>"Hello World!");
54
-
app.Run();
55
-
```
34
+
Call `services.AddHttpLogging()` during host construction.
0 commit comments