* Log correct message for Found/NotFound views
This commit is contained in:
parent
a1af85beb7
commit
ed46885586
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Mvc.Logging
|
||||||
{
|
{
|
||||||
public static class ViewComponentResultLoggerExtensions
|
public static class ViewComponentResultLoggerExtensions
|
||||||
{
|
{
|
||||||
private static Action<ILogger, string, string[], Exception> _viewComponentResultExecuting;
|
private static readonly Action<ILogger, string, string[], Exception> _viewComponentResultExecuting;
|
||||||
|
|
||||||
static ViewComponentResultLoggerExtensions()
|
static ViewComponentResultLoggerExtensions()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
@ -9,7 +10,9 @@ namespace Microsoft.AspNet.Mvc.Logging
|
||||||
{
|
{
|
||||||
public static class ViewResultExecutorLoggerExtensions
|
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()
|
static ViewResultExecutorLoggerExtensions()
|
||||||
{
|
{
|
||||||
|
|
@ -17,11 +20,30 @@ namespace Microsoft.AspNet.Mvc.Logging
|
||||||
LogLevel.Information,
|
LogLevel.Information,
|
||||||
1,
|
1,
|
||||||
"Executing ViewResult, running view at path {Path}.");
|
"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)
|
public static void ViewResultExecuting(this ILogger logger, IView view)
|
||||||
{
|
{
|
||||||
_viewResultExecuting(logger, view.Path, null);
|
_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.PartialViewFound(viewName);
|
Logger.ViewFound(viewName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
||||||
searchedLocations = result.SearchedLocations
|
searchedLocations = result.SearchedLocations
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Logger.PartialViewNotFound(viewName, result.SearchedLocations);
|
Logger.ViewNotFound(viewName, result.SearchedLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue