Skip to content

Log type of ObjectResult in ObjectResultExecutor #21425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2020
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 @@ -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);
Expand Down
33 changes: 21 additions & 12 deletions src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ internal static class MvcCoreLoggerExtensions
private static readonly Action<ILogger, string, Exception> _ambiguousActions;
private static readonly Action<ILogger, string, string, IActionConstraint, Exception> _constraintMismatch;

private static readonly Action<ILogger, FileResult, string, string, Exception> _executingFileResult;
private static readonly Action<ILogger, FileResult, string, Exception> _executingFileResultWithNoFileName;
private static readonly Action<ILogger, string, string, string, Exception> _executingFileResult;
private static readonly Action<ILogger, string, string, Exception> _executingFileResultWithNoFileName;
private static readonly Action<ILogger, Exception> _notEnabledForRangeProcessing;
private static readonly Action<ILogger, Exception> _writingRangeToBody;
private static readonly Action<ILogger, object, Exception> _authorizationFailure;
Expand All @@ -72,7 +72,7 @@ internal static class MvcCoreLoggerExtensions

private static readonly Action<ILogger, string, Exception> _localRedirectResultExecuting;

private static readonly Action<ILogger, string, Exception> _objectResultExecuting;
private static readonly Action<ILogger, string, string, Exception> _objectResultExecuting;
private static readonly Action<ILogger, IEnumerable<string>, Exception> _noFormatter;
private static readonly Action<ILogger, IOutputFormatter, string, Exception> _formatterSelected;
private static readonly Action<ILogger, string, Exception> _skippedContentNegotiation;
Expand Down Expand Up @@ -250,12 +250,12 @@ static MvcCoreLoggerExtensions()
new EventId(2, "ConstraintMismatch"),
"Action '{ActionName}' with id '{ActionId}' did not match the constraint '{ActionConstraint}'");

_executingFileResult = LoggerMessage.Define<FileResult, string, string>(
_executingFileResult = LoggerMessage.Define<string, string, string>(
LogLevel.Information,
new EventId(1, "ExecutingFileResult"),
"Executing {FileResultType}, sending file '{FileDownloadPath}' with download name '{FileDownloadName}' ...");

_executingFileResultWithNoFileName = LoggerMessage.Define<FileResult, string>(
_executingFileResultWithNoFileName = LoggerMessage.Define<string, string>(
LogLevel.Information,
new EventId(2, "ExecutingFileResultWithNoFileName"),
"Executing {FileResultType}, sending file with download name '{FileDownloadName}' ...");
Expand Down Expand Up @@ -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<string>(
_objectResultExecuting = LoggerMessage.Define<string, string>(
LogLevel.Information,
new EventId(1, "ObjectResultExecuting"),
"Executing ObjectResult, writing value of type '{Type}'.");
"Executing {ObjectResultType}, writing value of type '{Type}'.");

_formatterSelected = LoggerMessage.Define<IOutputFormatter, string>(
LogLevel.Debug,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1017,12 +1025,13 @@ 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);
var objectResultType = result.GetType().Name;
var valueType = value == null ? "null" : value.GetType().FullName;
_objectResultExecuting(logger, objectResultType, valueType, null);
}
}

Expand Down