Skip to content

Commit ad391ae

Browse files
committed
Include details about the controller action being executed
1 parent 070e855 commit ad391ae

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Mvc/Mvc.Core/src/Internal/MvcCoreLoggerExtensions.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ internal static class MvcCoreLoggerExtensions
3232
private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
3333

3434
private static readonly Action<ILogger, string, string, Exception> _actionExecuting;
35+
private static readonly Action<ILogger, string, MethodInfo, string, string, Exception> _controllerActionExecuting;
3536
private static readonly Action<ILogger, string, double, Exception> _actionExecuted;
3637

3738
private static readonly Action<ILogger, string[], Exception> _challengeResultExecuting;
@@ -153,6 +154,11 @@ static MvcCoreLoggerExtensions()
153154
1,
154155
"Route matched with {RouteData}. Executing action {ActionName}");
155156

157+
_controllerActionExecuting = LoggerMessage.Define<string, MethodInfo, string, string>(
158+
LogLevel.Information,
159+
3,
160+
"Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName}).");
161+
156162
_actionExecuted = LoggerMessage.Define<string, double>(
157163
LogLevel.Information,
158164
2,
@@ -683,7 +689,22 @@ public static void ExecutingAction(this ILogger logger, ActionDescriptor action)
683689
}
684690
}
685691

686-
_actionExecuting(logger, stringBuilder.ToString(), action.DisplayName, null);
692+
if (action is ControllerActionDescriptor controllerActionDescriptor)
693+
{
694+
var controllerType = controllerActionDescriptor.ControllerTypeInfo.AsType();
695+
var controllerName = TypeNameHelper.GetTypeDisplayName(controllerType);
696+
_controllerActionExecuting(
697+
logger,
698+
stringBuilder.ToString(),
699+
controllerActionDescriptor.MethodInfo,
700+
controllerName,
701+
controllerType.Assembly.GetName().Name,
702+
null);
703+
}
704+
else
705+
{
706+
_actionExecuting(logger, stringBuilder.ToString(), action.DisplayName, null);
707+
}
687708
}
688709
}
689710

0 commit comments

Comments
 (0)