File tree 2 files changed +6
-2
lines changed
src/Microsoft.AspNetCore.Hosting/Internal
2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ public Context CreateContext(IFeatureCollection contextFeatures)
75
75
return new Context
76
76
{
77
77
HttpContext = httpContext ,
78
- Scope = scope ,
78
+ Scope = scope , // Scope can be null if logging is not on.
79
79
StartTimestamp = startTimestamp ,
80
80
} ;
81
81
}
Original file line number Diff line number Diff line change @@ -15,7 +15,11 @@ internal static class HostingLoggerExtensions
15
15
{
16
16
public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext )
17
17
{
18
- return logger . BeginScope ( new HostingLogScope ( httpContext ) ) ;
18
+ // to avoid allocation, return a null scope if the logger is not on at least to some degree.
19
+ if ( logger . IsEnabled ( LogLevel . Critical ) )
20
+ return logger . BeginScope ( new HostingLogScope ( httpContext ) ) ;
21
+ else
22
+ return null ;
19
23
}
20
24
21
25
public static void ApplicationError ( this ILogger logger , Exception exception )
You can’t perform that action at this time.
0 commit comments