From 6d0807ceb10e5acadd557b84c058de2fc5c79ff7 Mon Sep 17 00:00:00 2001 From: Andrew J Said Date: Sat, 2 May 2020 15:40:21 +0100 Subject: [PATCH 1/2] Log type of ObjectResult in ObjectResultExecutor --- .../src/Infrastructure/ObjectResultExecutor.cs | 2 +- src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ObjectResultExecutor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ObjectResultExecutor.cs index 0fad09d57e6a..b0c5e28393f1 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ObjectResultExecutor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ObjectResultExecutor.cs @@ -155,7 +155,7 @@ private Task ExecuteAsyncCore(ActionContext context, ObjectResult result, Type o return Task.CompletedTask; } - Logger.ObjectResultExecuting(value); + Logger.ObjectResultExecuting(result, value); result.OnFormatting(context); return selectedFormatter.WriteAsync(formatterContext); diff --git a/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs b/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs index b9d632757788..0891d501402c 100644 --- a/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs +++ b/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs @@ -72,7 +72,7 @@ internal static class MvcCoreLoggerExtensions private static readonly Action _localRedirectResultExecuting; - private static readonly Action _objectResultExecuting; + private static readonly Action _objectResultExecuting; private static readonly Action, Exception> _noFormatter; private static readonly Action _formatterSelected; private static readonly Action _skippedContentNegotiation; @@ -315,10 +315,10 @@ static MvcCoreLoggerExtensions() new EventId(1, "NoFormatter"), "No output formatter was found for content types '{ContentTypes}' to write the response."); - _objectResultExecuting = LoggerMessage.Define( + _objectResultExecuting = LoggerMessage.Define( LogLevel.Information, new EventId(1, "ObjectResultExecuting"), - "Executing ObjectResult, writing value of type '{Type}'."); + "Executing {ObjectResultType}, writing value of type '{Type}'."); _formatterSelected = LoggerMessage.Define( LogLevel.Debug, @@ -1017,12 +1017,12 @@ public static void LocalRedirectResultExecuting(this ILogger logger, string dest _localRedirectResultExecuting(logger, destination, null); } - public static void ObjectResultExecuting(this ILogger logger, object value) + public static void ObjectResultExecuting(this ILogger logger, ObjectResult result, object value) { if (logger.IsEnabled(LogLevel.Information)) { var type = value == null ? "null" : value.GetType().FullName; - _objectResultExecuting(logger, type, null); + _objectResultExecuting(logger, result, type, null); } } From e7af4e08f00cdff41c0d9732c9f3c171ca04f1e2 Mon Sep 17 00:00:00 2001 From: Andrew J Said Date: Mon, 4 May 2020 20:42:08 +0100 Subject: [PATCH 2/2] Log only class name of FileResult, ObjectResult types --- .../Mvc.Core/src/MvcCoreLoggerExtensions.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs b/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs index 0891d501402c..e4ee95d0dba1 100644 --- a/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs +++ b/src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs @@ -54,8 +54,8 @@ internal static class MvcCoreLoggerExtensions private static readonly Action _ambiguousActions; private static readonly Action _constraintMismatch; - private static readonly Action _executingFileResult; - private static readonly Action _executingFileResultWithNoFileName; + private static readonly Action _executingFileResult; + private static readonly Action _executingFileResultWithNoFileName; private static readonly Action _notEnabledForRangeProcessing; private static readonly Action _writingRangeToBody; private static readonly Action _authorizationFailure; @@ -72,7 +72,7 @@ internal static class MvcCoreLoggerExtensions private static readonly Action _localRedirectResultExecuting; - private static readonly Action _objectResultExecuting; + private static readonly Action _objectResultExecuting; private static readonly Action, Exception> _noFormatter; private static readonly Action _formatterSelected; private static readonly Action _skippedContentNegotiation; @@ -250,12 +250,12 @@ static MvcCoreLoggerExtensions() new EventId(2, "ConstraintMismatch"), "Action '{ActionName}' with id '{ActionId}' did not match the constraint '{ActionConstraint}'"); - _executingFileResult = LoggerMessage.Define( + _executingFileResult = LoggerMessage.Define( LogLevel.Information, new EventId(1, "ExecutingFileResult"), "Executing {FileResultType}, sending file '{FileDownloadPath}' with download name '{FileDownloadName}' ..."); - _executingFileResultWithNoFileName = LoggerMessage.Define( + _executingFileResultWithNoFileName = LoggerMessage.Define( LogLevel.Information, new EventId(2, "ExecutingFileResultWithNoFileName"), "Executing {FileResultType}, sending file with download name '{FileDownloadName}' ..."); @@ -315,7 +315,7 @@ static MvcCoreLoggerExtensions() new EventId(1, "NoFormatter"), "No output formatter was found for content types '{ContentTypes}' to write the response."); - _objectResultExecuting = LoggerMessage.Define( + _objectResultExecuting = LoggerMessage.Define( LogLevel.Information, new EventId(1, "ObjectResultExecuting"), "Executing {ObjectResultType}, writing value of type '{Type}'."); @@ -933,12 +933,20 @@ public static void ConstraintMismatch( public static void ExecutingFileResult(this ILogger logger, FileResult fileResult) { - _executingFileResultWithNoFileName(logger, fileResult, fileResult.FileDownloadName, null); + if (logger.IsEnabled(LogLevel.Information)) + { + var fileResultType = fileResult.GetType().Name; + _executingFileResultWithNoFileName(logger, fileResultType, fileResult.FileDownloadName, null); + } } public static void ExecutingFileResult(this ILogger logger, FileResult fileResult, string fileName) { - _executingFileResult(logger, fileResult, fileName, fileResult.FileDownloadName, null); + if (logger.IsEnabled(LogLevel.Information)) + { + var fileResultType = fileResult.GetType().Name; + _executingFileResult(logger, fileResultType, fileName, fileResult.FileDownloadName, null); + } } public static void NotEnabledForRangeProcessing(this ILogger logger) @@ -1021,8 +1029,9 @@ public static void ObjectResultExecuting(this ILogger logger, ObjectResult resul { if (logger.IsEnabled(LogLevel.Information)) { - var type = value == null ? "null" : value.GetType().FullName; - _objectResultExecuting(logger, result, type, null); + var objectResultType = result.GetType().Name; + var valueType = value == null ? "null" : value.GetType().FullName; + _objectResultExecuting(logger, objectResultType, valueType, null); } }