[Perf] Check for Logger.IsEnabled in logging methods of MvcCoreLoggerExtensions
Fixes #4466
This commit is contained in:
parent
1f93977729
commit
73dc7bf48b
|
|
@ -213,12 +213,15 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
public static void ExecutedAction(this ILogger logger, ActionDescriptor action, long startTimestamp)
|
public static void ExecutedAction(this ILogger logger, ActionDescriptor action, long startTimestamp)
|
||||||
{
|
{
|
||||||
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
|
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
|
||||||
if (startTimestamp != 0)
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
{
|
{
|
||||||
var currentTimestamp = Stopwatch.GetTimestamp();
|
if (startTimestamp != 0)
|
||||||
var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp)));
|
{
|
||||||
|
var currentTimestamp = Stopwatch.GetTimestamp();
|
||||||
|
var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp)));
|
||||||
|
|
||||||
_actionExecuted(logger, action.DisplayName, elapsed.TotalMilliseconds, null);
|
_actionExecuted(logger, action.DisplayName, elapsed.TotalMilliseconds, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,7 +232,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
|
|
||||||
public static void ChallengeResultExecuting(this ILogger logger, IList<string> schemes)
|
public static void ChallengeResultExecuting(this ILogger logger, IList<string> schemes)
|
||||||
{
|
{
|
||||||
_challengeResultExecuting(logger, schemes.ToArray(), null);
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
|
{
|
||||||
|
_challengeResultExecuting(logger, schemes.ToArray(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ContentResultExecuting(this ILogger logger, string contentType)
|
public static void ContentResultExecuting(this ILogger logger, string contentType)
|
||||||
|
|
@ -265,8 +271,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
|
|
||||||
public static void ActionMethodExecuted(this ILogger logger, ActionExecutingContext context, IActionResult result)
|
public static void ActionMethodExecuted(this ILogger logger, ActionExecutingContext context, IActionResult result)
|
||||||
{
|
{
|
||||||
var actionName = context.ActionDescriptor.DisplayName;
|
if (logger.IsEnabled(LogLevel.Debug))
|
||||||
_actionMethodExecuted(logger, actionName, Convert.ToString(result), null);
|
{
|
||||||
|
var actionName = context.ActionDescriptor.DisplayName;
|
||||||
|
_actionMethodExecuted(logger, actionName, Convert.ToString(result), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AmbiguousActions(this ILogger logger, string actionNames)
|
public static void AmbiguousActions(this ILogger logger, string actionNames)
|
||||||
|
|
@ -318,7 +327,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
|
|
||||||
public static void ForbidResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
|
public static void ForbidResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
|
||||||
{
|
{
|
||||||
_forbidResultExecuting(logger, authenticationSchemes.ToArray(), null);
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
|
{
|
||||||
|
_forbidResultExecuting(logger, authenticationSchemes.ToArray(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SignInResultExecuting(this ILogger logger, string authenticationScheme, ClaimsPrincipal principal)
|
public static void SignInResultExecuting(this ILogger logger, string authenticationScheme, ClaimsPrincipal principal)
|
||||||
|
|
@ -328,7 +340,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
|
|
||||||
public static void SignOutResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
|
public static void SignOutResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
|
||||||
{
|
{
|
||||||
_signOutResultExecuting(logger, authenticationSchemes.ToArray(), null);
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
|
{
|
||||||
|
_signOutResultExecuting(logger, authenticationSchemes.ToArray(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HttpStatusCodeResultExecuting(this ILogger logger, int statusCode)
|
public static void HttpStatusCodeResultExecuting(this ILogger logger, int statusCode)
|
||||||
|
|
@ -343,14 +358,20 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
|
|
||||||
public static void ObjectResultExecuting(this ILogger logger, object value)
|
public static void ObjectResultExecuting(this ILogger logger, object value)
|
||||||
{
|
{
|
||||||
_objectResultExecuting(logger, Convert.ToString(value), null);
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
|
{
|
||||||
|
_objectResultExecuting(logger, Convert.ToString(value), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NoFormatter(
|
public static void NoFormatter(
|
||||||
this ILogger logger,
|
this ILogger logger,
|
||||||
OutputFormatterWriteContext formatterContext)
|
OutputFormatterWriteContext formatterContext)
|
||||||
{
|
{
|
||||||
_noFormatter(logger, Convert.ToString(formatterContext.ContentType), null);
|
if (logger.IsEnabled(LogLevel.Warning))
|
||||||
|
{
|
||||||
|
_noFormatter(logger, Convert.ToString(formatterContext.ContentType), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FormatterSelected(
|
public static void FormatterSelected(
|
||||||
|
|
@ -358,8 +379,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
IOutputFormatter outputFormatter,
|
IOutputFormatter outputFormatter,
|
||||||
OutputFormatterWriteContext context)
|
OutputFormatterWriteContext context)
|
||||||
{
|
{
|
||||||
var contentType = Convert.ToString(context.ContentType);
|
if (logger.IsEnabled(LogLevel.Debug))
|
||||||
_formatterSelected(logger, outputFormatter, contentType, null);
|
{
|
||||||
|
var contentType = Convert.ToString(context.ContentType);
|
||||||
|
_formatterSelected(logger, outputFormatter, contentType, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SkippedContentNegotiation(this ILogger logger, string contentType)
|
public static void SkippedContentNegotiation(this ILogger logger, string contentType)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue