Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Logging optimization.2 14 #944

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Context CreateContext(IFeatureCollection contextFeatures)
return new Context
{
HttpContext = httpContext,
Scope = scope,
Scope = scope, // Scope can be null if logging is not on.
StartTimestamp = startTimestamp,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ internal static class HostingLoggerExtensions

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test better before the RequestScope call to in CreateContext?

return logger.BeginScope(new HostingLogScope(httpContext));
else
return null;
}

public static void RequestStarting(this ILogger logger, HttpContext httpContext)
Expand Down