* Log correct message for Found/NotFound views

This commit is contained in:
ryanbrandenburg 2015-11-12 10:46:14 -08:00
parent a1af85beb7
commit ed46885586
3 changed files with 26 additions and 4 deletions

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Mvc.Logging
{
public static class ViewComponentResultLoggerExtensions
{
private static Action<ILogger, string, string[], Exception> _viewComponentResultExecuting;
private static readonly Action<ILogger, string, string[], Exception> _viewComponentResultExecuting;
static ViewComponentResultLoggerExtensions()
{

View File

@ -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<ILogger, string, Exception> _viewResultExecuting;
private static readonly Action<ILogger, string, Exception> _viewResultExecuting;
private static readonly Action<ILogger, string, Exception> _viewFound;
private static readonly Action<ILogger, string, IEnumerable<string>, 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<string>(
LogLevel.Verbose,
2,
"The view '{ViewName}' was found.");
_viewNotFound = LoggerMessage.Define<string, IEnumerable<string>>(
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<string> searchedLocations)
{
_viewNotFound(logger, viewName, searchedLocations, null);
}
}
}

View File

@ -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;