File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
src/Microsoft.AspNetCore.Hosting/Internal Expand file tree Collapse file tree 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)
7575 return new Context
7676 {
7777 HttpContext = httpContext ,
78- Scope = scope ,
78+ Scope = scope , // Scope can be null if logging is not on.
7979 StartTimestamp = startTimestamp ,
8080 } ;
8181 }
Original file line number Diff line number Diff line change @@ -15,7 +15,11 @@ internal static class HostingLoggerExtensions
1515 {
1616 public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext )
1717 {
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 ;
1923 }
2024
2125 public static void ApplicationError ( this ILogger logger , Exception exception )
You can’t perform that action at this time.
0 commit comments