From ed4688558678605b25dc8405eca0cdab507c00f3 Mon Sep 17 00:00:00 2001 From: ryanbrandenburg Date: Thu, 12 Nov 2015 10:46:14 -0800 Subject: [PATCH] * Log correct message for Found/NotFound views --- .../ViewComponentResultLoggerExtensions.cs | 2 +- .../ViewResultExecutorLoggerExtensions.cs | 24 ++++++++++++++++++- .../ViewFeatures/ViewResultExecutor.cs | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewComponentResultLoggerExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewComponentResultLoggerExtensions.cs index ce27cbaf71..2ed984060c 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewComponentResultLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewComponentResultLoggerExtensions.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Mvc.Logging { public static class ViewComponentResultLoggerExtensions { - private static Action _viewComponentResultExecuting; + private static readonly Action _viewComponentResultExecuting; static ViewComponentResultLoggerExtensions() { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewResultExecutorLoggerExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewResultExecutorLoggerExtensions.cs index 17ad2ca211..19ce4be642 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewResultExecutorLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Logging/ViewResultExecutorLoggerExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.Extensions.Logging; @@ -9,7 +10,9 @@ namespace Microsoft.AspNet.Mvc.Logging { public static class ViewResultExecutorLoggerExtensions { - private static Action _viewResultExecuting; + private static readonly Action _viewResultExecuting; + private static readonly Action _viewFound; + private static readonly Action, Exception> _viewNotFound; static ViewResultExecutorLoggerExtensions() { @@ -17,11 +20,30 @@ namespace Microsoft.AspNet.Mvc.Logging LogLevel.Information, 1, "Executing ViewResult, running view at path {Path}."); + _viewFound = LoggerMessage.Define( + LogLevel.Verbose, + 2, + "The view '{ViewName}' was found."); + _viewNotFound = LoggerMessage.Define>( + LogLevel.Error, + 3, + "The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}"); } public static void ViewResultExecuting(this ILogger logger, IView view) { _viewResultExecuting(logger, view.Path, null); } + + public static void ViewFound(this ILogger logger, string viewName) + { + _viewFound(logger, viewName, null); + } + + public static void ViewNotFound(this ILogger logger, string viewName, + IEnumerable searchedLocations) + { + _viewNotFound(logger, viewName, searchedLocations, null); + } } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs index 9020f513c2..ced91f96b9 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures }); } - Logger.PartialViewFound(viewName); + Logger.ViewFound(viewName); } else { @@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures searchedLocations = result.SearchedLocations }); } - Logger.PartialViewNotFound(viewName, result.SearchedLocations); + Logger.ViewNotFound(viewName, result.SearchedLocations); } return result;