Logging optimization.2 14 (#944)
* Trivial change to avoid an allocation when logging is off (normal case).
This commit is contained in:
parent
f79904404e
commit
8165609f4e
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
|||
return new Context
|
||||
{
|
||||
HttpContext = httpContext,
|
||||
Scope = scope,
|
||||
Scope = scope, // Scope can be null if logging is not on.
|
||||
StartTimestamp = startTimestamp,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,11 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
|||
{
|
||||
public static IDisposable RequestScope(this ILogger logger, HttpContext httpContext)
|
||||
{
|
||||
return logger.BeginScope(new HostingLogScope(httpContext));
|
||||
// to avoid allocation, return a null scope if the logger is not on at least to some degree.
|
||||
if (logger.IsEnabled(LogLevel.Critical))
|
||||
return logger.BeginScope(new HostingLogScope(httpContext));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ApplicationError(this ILogger logger, Exception exception)
|
||||
|
|
|
|||
Loading…
Reference in New Issue