Zero cost(ish) diagnositcs when disabled

Inlinable fast-path check if Diagnositcs is enabled
This commit is contained in:
Ben Adams 2018-08-28 14:05:49 -07:00 committed by Pranav K
parent 98c10b6879
commit 2414db256f
36 changed files with 960 additions and 395 deletions

View File

@ -26,12 +26,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
internal ControllerActionInvoker( internal ControllerActionInvoker(
ILogger logger, ILogger logger,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper, IActionResultTypeMapper mapper,
ControllerContext controllerContext, ControllerContext controllerContext,
ControllerActionInvokerCacheEntry cacheEntry, ControllerActionInvokerCacheEntry cacheEntry,
IFilterMetadata[] filters) IFilterMetadata[] filters)
: base(diagnosticSource, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories) : base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
{ {
if (cacheEntry == null) if (cacheEntry == null)
{ {
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAsyncActionFilter)state; var filter = (IAsyncActionFilter)state;
var actionExecutingContext = _actionExecutingContext; var actionExecutingContext = _actionExecutingContext;
_diagnosticSource.BeforeOnActionExecution(actionExecutingContext, filter); _diagnosticListener.BeforeOnActionExecution(actionExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IAsyncActionFilter.OnActionExecutionAsync), nameof(IAsyncActionFilter.OnActionExecutionAsync),
@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
}; };
} }
_diagnosticSource.AfterOnActionExecution(_actionExecutedContext, filter); _diagnosticListener.AfterOnActionExecution(_actionExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IAsyncActionFilter.OnActionExecutionAsync), nameof(IAsyncActionFilter.OnActionExecutionAsync),
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IActionFilter)state; var filter = (IActionFilter)state;
var actionExecutingContext = _actionExecutingContext; var actionExecutingContext = _actionExecutingContext;
_diagnosticSource.BeforeOnActionExecuting(actionExecutingContext, filter); _diagnosticListener.BeforeOnActionExecuting(actionExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuting), nameof(IActionFilter.OnActionExecuting),
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnActionExecuting(actionExecutingContext); filter.OnActionExecuting(actionExecutingContext);
_diagnosticSource.AfterOnActionExecuting(actionExecutingContext, filter); _diagnosticListener.AfterOnActionExecuting(actionExecutingContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuting), nameof(IActionFilter.OnActionExecuting),
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IActionFilter)state; var filter = (IActionFilter)state;
var actionExecutedContext = _actionExecutedContext; var actionExecutedContext = _actionExecutedContext;
_diagnosticSource.BeforeOnActionExecuted(actionExecutedContext, filter); _diagnosticListener.BeforeOnActionExecuted(actionExecutedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuted), nameof(IActionFilter.OnActionExecuted),
@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnActionExecuted(actionExecutedContext); filter.OnActionExecuted(actionExecutedContext);
_diagnosticSource.AfterOnActionExecuted(actionExecutedContext, filter); _diagnosticListener.AfterOnActionExecuted(actionExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter, MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuted), nameof(IActionFilter.OnActionExecuted),
@ -335,13 +335,13 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var actionMethodExecutor = _cacheEntry.ActionMethodExecutor; var actionMethodExecutor = _cacheEntry.ActionMethodExecutor;
var orderedArguments = PrepareArguments(arguments, objectMethodExecutor); var orderedArguments = PrepareArguments(arguments, objectMethodExecutor);
var diagnosticSource = _diagnosticSource; var diagnosticListener = _diagnosticListener;
var logger = _logger; var logger = _logger;
IActionResult result = null; IActionResult result = null;
try try
{ {
diagnosticSource.BeforeActionMethod( diagnosticListener.BeforeActionMethod(
controllerContext, controllerContext,
arguments, arguments,
controller); controller);
@ -362,7 +362,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
} }
finally finally
{ {
diagnosticSource.AfterActionMethod( diagnosticListener.AfterActionMethod(
controllerContext, controllerContext,
arguments, arguments,
controllerContext, controllerContext,

View File

@ -19,21 +19,21 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
private readonly IReadOnlyList<IValueProviderFactory> _valueProviderFactories; private readonly IReadOnlyList<IValueProviderFactory> _valueProviderFactories;
private readonly int _maxModelValidationErrors; private readonly int _maxModelValidationErrors;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
private readonly IActionResultTypeMapper _mapper; private readonly IActionResultTypeMapper _mapper;
public ControllerActionInvokerProvider( public ControllerActionInvokerProvider(
ControllerActionInvokerCache controllerActionInvokerCache, ControllerActionInvokerCache controllerActionInvokerCache,
IOptions<MvcOptions> optionsAccessor, IOptions<MvcOptions> optionsAccessor,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper) IActionResultTypeMapper mapper)
{ {
_controllerActionInvokerCache = controllerActionInvokerCache; _controllerActionInvokerCache = controllerActionInvokerCache;
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
_maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors; _maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>(); _logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_mapper = mapper; _mapper = mapper;
} }
@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var invoker = new ControllerActionInvoker( var invoker = new ControllerActionInvoker(
_logger, _logger,
_diagnosticSource, _diagnosticListener,
_mapper, _mapper,
controllerContext, controllerContext,
cacheResult.cacheEntry, cacheResult.cacheEntry,

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{ {
internal abstract class ResourceInvoker internal abstract class ResourceInvoker
{ {
protected readonly DiagnosticSource _diagnosticSource; protected readonly DiagnosticListener _diagnosticListener;
protected readonly ILogger _logger; protected readonly ILogger _logger;
protected readonly IActionResultTypeMapper _mapper; protected readonly IActionResultTypeMapper _mapper;
protected readonly ActionContext _actionContext; protected readonly ActionContext _actionContext;
@ -37,14 +37,14 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
protected object _instance; protected object _instance;
public ResourceInvoker( public ResourceInvoker(
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILogger logger, ILogger logger,
IActionResultTypeMapper mapper, IActionResultTypeMapper mapper,
ActionContext actionContext, ActionContext actionContext,
IFilterMetadata[] filters, IFilterMetadata[] filters,
IList<IValueProviderFactory> valueProviderFactories) IList<IValueProviderFactory> valueProviderFactories)
{ {
_diagnosticSource = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource)); _diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener));
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_actionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext)); _actionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext));
@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{ {
try try
{ {
_diagnosticSource.BeforeAction( _diagnosticListener.BeforeAction(
_actionContext.ActionDescriptor, _actionContext.ActionDescriptor,
_actionContext.HttpContext, _actionContext.HttpContext,
_actionContext.RouteData); _actionContext.RouteData);
@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
} }
finally finally
{ {
_diagnosticSource.AfterAction( _diagnosticListener.AfterAction(
_actionContext.ActionDescriptor, _actionContext.ActionDescriptor,
_actionContext.HttpContext, _actionContext.HttpContext,
_actionContext.RouteData); _actionContext.RouteData);
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{ {
var actionContext = _actionContext; var actionContext = _actionContext;
_diagnosticSource.BeforeActionResult(actionContext, result); _diagnosticListener.BeforeActionResult(actionContext, result);
_logger.BeforeExecutingActionResult(result); _logger.BeforeExecutingActionResult(result);
try try
@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
} }
finally finally
{ {
_diagnosticSource.AfterActionResult(actionContext, result); _diagnosticListener.AfterActionResult(actionContext, result);
_logger.AfterExecutingActionResult(result); _logger.AfterExecutingActionResult(result);
} }
} }
@ -195,7 +195,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAsyncAuthorizationFilter)state; var filter = (IAsyncAuthorizationFilter)state;
var authorizationContext = _authorizationContext; var authorizationContext = _authorizationContext;
_diagnosticSource.BeforeOnAuthorizationAsync(authorizationContext, filter); _diagnosticListener.BeforeOnAuthorizationAsync(authorizationContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.AuthorizationFilter, FilterTypeConstants.AuthorizationFilter,
nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync), nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync),
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAsyncAuthorizationFilter)state; var filter = (IAsyncAuthorizationFilter)state;
var authorizationContext = _authorizationContext; var authorizationContext = _authorizationContext;
_diagnosticSource.AfterOnAuthorizationAsync(authorizationContext, filter); _diagnosticListener.AfterOnAuthorizationAsync(authorizationContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.AuthorizationFilter, FilterTypeConstants.AuthorizationFilter,
nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync), nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync),
@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAuthorizationFilter)state; var filter = (IAuthorizationFilter)state;
var authorizationContext = _authorizationContext; var authorizationContext = _authorizationContext;
_diagnosticSource.BeforeOnAuthorization(authorizationContext, filter); _diagnosticListener.BeforeOnAuthorization(authorizationContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.AuthorizationFilter, FilterTypeConstants.AuthorizationFilter,
nameof(IAuthorizationFilter.OnAuthorization), nameof(IAuthorizationFilter.OnAuthorization),
@ -249,7 +249,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnAuthorization(authorizationContext); filter.OnAuthorization(authorizationContext);
_diagnosticSource.AfterOnAuthorization(authorizationContext, filter); _diagnosticListener.AfterOnAuthorization(authorizationContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.AuthorizationFilter, FilterTypeConstants.AuthorizationFilter,
nameof(IAuthorizationFilter.OnAuthorization), nameof(IAuthorizationFilter.OnAuthorization),
@ -332,7 +332,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAsyncResourceFilter)state; var filter = (IAsyncResourceFilter)state;
var resourceExecutingContext = _resourceExecutingContext; var resourceExecutingContext = _resourceExecutingContext;
_diagnosticSource.BeforeOnResourceExecution(resourceExecutingContext, filter); _diagnosticListener.BeforeOnResourceExecution(resourceExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IAsyncResourceFilter.OnResourceExecutionAsync), nameof(IAsyncResourceFilter.OnResourceExecutionAsync),
@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
Result = _resourceExecutingContext.Result, Result = _resourceExecutingContext.Result,
}; };
_diagnosticSource.AfterOnResourceExecution(_resourceExecutedContext, filter); _diagnosticListener.AfterOnResourceExecution(_resourceExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IAsyncResourceFilter.OnResourceExecutionAsync), nameof(IAsyncResourceFilter.OnResourceExecutionAsync),
@ -387,7 +387,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IResourceFilter)state; var filter = (IResourceFilter)state;
var resourceExecutingContext = _resourceExecutingContext; var resourceExecutingContext = _resourceExecutingContext;
_diagnosticSource.BeforeOnResourceExecuting(resourceExecutingContext, filter); _diagnosticListener.BeforeOnResourceExecuting(resourceExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IResourceFilter.OnResourceExecuting), nameof(IResourceFilter.OnResourceExecuting),
@ -395,7 +395,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnResourceExecuting(resourceExecutingContext); filter.OnResourceExecuting(resourceExecutingContext);
_diagnosticSource.AfterOnResourceExecuting(resourceExecutingContext, filter); _diagnosticListener.AfterOnResourceExecuting(resourceExecutingContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IResourceFilter.OnResourceExecuting), nameof(IResourceFilter.OnResourceExecuting),
@ -431,7 +431,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IResourceFilter)state; var filter = (IResourceFilter)state;
var resourceExecutedContext = _resourceExecutedContext; var resourceExecutedContext = _resourceExecutedContext;
_diagnosticSource.BeforeOnResourceExecuted(resourceExecutedContext, filter); _diagnosticListener.BeforeOnResourceExecuted(resourceExecutedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IResourceFilter.OnResourceExecuted), nameof(IResourceFilter.OnResourceExecuted),
@ -439,7 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnResourceExecuted(resourceExecutedContext); filter.OnResourceExecuted(resourceExecutedContext);
_diagnosticSource.AfterOnResourceExecuted(resourceExecutedContext, filter); _diagnosticListener.AfterOnResourceExecuted(resourceExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.ResourceFilter, FilterTypeConstants.ResourceFilter,
nameof(IResourceFilter.OnResourceExecuted), nameof(IResourceFilter.OnResourceExecuted),
@ -527,7 +527,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
// we'll call the filter. Otherwise there's nothing to do. // we'll call the filter. Otherwise there's nothing to do.
if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled) if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled)
{ {
_diagnosticSource.BeforeOnExceptionAsync(exceptionContext, filter); _diagnosticListener.BeforeOnExceptionAsync(exceptionContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.ExceptionFilter, FilterTypeConstants.ExceptionFilter,
nameof(IAsyncExceptionFilter.OnExceptionAsync), nameof(IAsyncExceptionFilter.OnExceptionAsync),
@ -554,7 +554,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (IAsyncExceptionFilter)state; var filter = (IAsyncExceptionFilter)state;
var exceptionContext = _exceptionContext; var exceptionContext = _exceptionContext;
_diagnosticSource.AfterOnExceptionAsync(exceptionContext, filter); _diagnosticListener.AfterOnExceptionAsync(exceptionContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.ExceptionFilter, FilterTypeConstants.ExceptionFilter,
nameof(IAsyncExceptionFilter.OnExceptionAsync), nameof(IAsyncExceptionFilter.OnExceptionAsync),
@ -594,7 +594,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
// we'll call the filter. Otherwise there's nothing to do. // we'll call the filter. Otherwise there's nothing to do.
if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled) if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled)
{ {
_diagnosticSource.BeforeOnException(exceptionContext, filter); _diagnosticListener.BeforeOnException(exceptionContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
FilterTypeConstants.ExceptionFilter, FilterTypeConstants.ExceptionFilter,
nameof(IExceptionFilter.OnException), nameof(IExceptionFilter.OnException),
@ -602,7 +602,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnException(exceptionContext); filter.OnException(exceptionContext);
_diagnosticSource.AfterOnException(exceptionContext, filter); _diagnosticListener.AfterOnException(exceptionContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
FilterTypeConstants.ExceptionFilter, FilterTypeConstants.ExceptionFilter,
nameof(IExceptionFilter.OnException), nameof(IExceptionFilter.OnException),
@ -904,7 +904,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (TFilterAsync)state; var filter = (TFilterAsync)state;
var resultExecutingContext = _resultExecutingContext; var resultExecutingContext = _resultExecutingContext;
_diagnosticSource.BeforeOnResultExecution(resultExecutingContext, filter); _diagnosticListener.BeforeOnResultExecution(resultExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IAsyncResultFilter.OnResultExecutionAsync), nameof(IAsyncResultFilter.OnResultExecutionAsync),
@ -944,7 +944,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
}; };
} }
_diagnosticSource.AfterOnResultExecution(_resultExecutedContext, filter); _diagnosticListener.AfterOnResultExecution(_resultExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IAsyncResultFilter.OnResultExecutionAsync), nameof(IAsyncResultFilter.OnResultExecutionAsync),
@ -961,7 +961,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (TFilter)state; var filter = (TFilter)state;
var resultExecutingContext = _resultExecutingContext; var resultExecutingContext = _resultExecutingContext;
_diagnosticSource.BeforeOnResultExecuting(resultExecutingContext, filter); _diagnosticListener.BeforeOnResultExecuting(resultExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IResultFilter.OnResultExecuting), nameof(IResultFilter.OnResultExecuting),
@ -969,7 +969,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnResultExecuting(resultExecutingContext); filter.OnResultExecuting(resultExecutingContext);
_diagnosticSource.AfterOnResultExecuting(resultExecutingContext, filter); _diagnosticListener.AfterOnResultExecuting(resultExecutingContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IResultFilter.OnResultExecuting), nameof(IResultFilter.OnResultExecuting),
@ -1011,7 +1011,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
var filter = (TFilter)state; var filter = (TFilter)state;
var resultExecutedContext = _resultExecutedContext; var resultExecutedContext = _resultExecutedContext;
_diagnosticSource.BeforeOnResultExecuted(resultExecutedContext, filter); _diagnosticListener.BeforeOnResultExecuted(resultExecutedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IResultFilter.OnResultExecuted), nameof(IResultFilter.OnResultExecuted),
@ -1019,7 +1019,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
filter.OnResultExecuted(resultExecutedContext); filter.OnResultExecuted(resultExecutedContext);
_diagnosticSource.AfterOnResultExecuted(resultExecutedContext, filter); _diagnosticListener.AfterOnResultExecuted(resultExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
resultFilterKind, resultFilterKind,
nameof(IResultFilter.OnResultExecuted), nameof(IResultFilter.OnResultExecuted),

View File

@ -16,55 +16,82 @@ namespace Microsoft.AspNetCore.Mvc
internal static class MvcCoreDiagnosticSourceExtensions internal static class MvcCoreDiagnosticSourceExtensions
{ {
public static void BeforeAction( public static void BeforeAction(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionDescriptor actionDescriptor, ActionDescriptor actionDescriptor,
HttpContext httpContext, HttpContext httpContext,
RouteData routeData) RouteData routeData)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionDescriptor != null); Debug.Assert(actionDescriptor != null);
Debug.Assert(httpContext != null); Debug.Assert(httpContext != null);
Debug.Assert(routeData != null); Debug.Assert(routeData != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeAction")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeActionImpl(diagnosticListener, actionDescriptor, httpContext, routeData);
}
}
private static void BeforeActionImpl(DiagnosticListener diagnosticListener, ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeAction"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeAction", "Microsoft.AspNetCore.Mvc.BeforeAction",
new { actionDescriptor, httpContext = httpContext, routeData = routeData }); new { actionDescriptor, httpContext = httpContext, routeData = routeData });
} }
} }
public static void AfterAction( public static void AfterAction(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionDescriptor actionDescriptor, ActionDescriptor actionDescriptor,
HttpContext httpContext, HttpContext httpContext,
RouteData routeData) RouteData routeData)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionDescriptor != null); Debug.Assert(actionDescriptor != null);
Debug.Assert(httpContext != null); Debug.Assert(httpContext != null);
Debug.Assert(routeData != null); Debug.Assert(routeData != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterAction")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterActionImpl(diagnosticListener, actionDescriptor, httpContext, routeData);
}
}
private static void AfterActionImpl(DiagnosticListener diagnosticListener, ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterAction"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterAction", "Microsoft.AspNetCore.Mvc.AfterAction",
new { actionDescriptor, httpContext = httpContext, routeData = routeData }); new { actionDescriptor, httpContext = httpContext, routeData = routeData });
} }
} }
public static void BeforeOnAuthorizationAsync( public static void BeforeOnAuthorizationAsync(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
AuthorizationFilterContext authorizationContext, AuthorizationFilterContext authorizationContext,
IAsyncAuthorizationFilter filter) IAsyncAuthorizationFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(authorizationContext != null); Debug.Assert(authorizationContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnAuthorizationAsyncImpl(diagnosticListener, authorizationContext, filter);
}
}
private static void BeforeOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization",
new new
{ {
@ -76,17 +103,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnAuthorizationAsync( public static void AfterOnAuthorizationAsync(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
AuthorizationFilterContext authorizationContext, AuthorizationFilterContext authorizationContext,
IAsyncAuthorizationFilter filter) IAsyncAuthorizationFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(authorizationContext != null); Debug.Assert(authorizationContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnAuthorizationAsyncImpl(diagnosticListener, authorizationContext, filter);
}
}
private static void AfterOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnAuthorization", "Microsoft.AspNetCore.Mvc.AfterOnAuthorization",
new new
{ {
@ -98,17 +134,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnAuthorization( public static void BeforeOnAuthorization(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
AuthorizationFilterContext authorizationContext, AuthorizationFilterContext authorizationContext,
IAuthorizationFilter filter) IAuthorizationFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(authorizationContext != null); Debug.Assert(authorizationContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnAuthorizationImpl(diagnosticListener, authorizationContext, filter);
}
}
private static void BeforeOnAuthorizationImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAuthorizationFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization",
new new
{ {
@ -120,17 +165,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnAuthorization( public static void AfterOnAuthorization(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
AuthorizationFilterContext authorizationContext, AuthorizationFilterContext authorizationContext,
IAuthorizationFilter filter) IAuthorizationFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(authorizationContext != null); Debug.Assert(authorizationContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnAuthorizationImpl(diagnosticListener, authorizationContext, filter);
}
}
private static void AfterOnAuthorizationImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAuthorizationFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnAuthorization", "Microsoft.AspNetCore.Mvc.AfterOnAuthorization",
new new
{ {
@ -142,17 +196,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResourceExecution( public static void BeforeOnResourceExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutingContext resourceExecutingContext, ResourceExecutingContext resourceExecutingContext,
IAsyncResourceFilter filter) IAsyncResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutingContext != null); Debug.Assert(resourceExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResourceExecutionImpl(diagnosticListener, resourceExecutingContext, filter);
}
}
private static void BeforeOnResourceExecutionImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IAsyncResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution", "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution",
new new
{ {
@ -164,17 +227,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResourceExecution( public static void AfterOnResourceExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutedContext resourceExecutedContext, ResourceExecutedContext resourceExecutedContext,
IAsyncResourceFilter filter) IAsyncResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutedContext != null); Debug.Assert(resourceExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResourceExecutionImpl(diagnosticListener, resourceExecutedContext, filter);
}
}
private static void AfterOnResourceExecutionImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IAsyncResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResourceExecution", "Microsoft.AspNetCore.Mvc.AfterOnResourceExecution",
new new
{ {
@ -186,17 +258,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResourceExecuting( public static void BeforeOnResourceExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutingContext resourceExecutingContext, ResourceExecutingContext resourceExecutingContext,
IResourceFilter filter) IResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutingContext != null); Debug.Assert(resourceExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResourceExecutingImpl(diagnosticListener, resourceExecutingContext, filter);
}
}
private static void BeforeOnResourceExecutingImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting", "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting",
new new
{ {
@ -208,17 +289,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResourceExecuting( public static void AfterOnResourceExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutingContext resourceExecutingContext, ResourceExecutingContext resourceExecutingContext,
IResourceFilter filter) IResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutingContext != null); Debug.Assert(resourceExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResourceExecutingImpl(diagnosticListener, resourceExecutingContext, filter);
}
}
private static void AfterOnResourceExecutingImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting", "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting",
new new
{ {
@ -230,17 +320,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResourceExecuted( public static void BeforeOnResourceExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutedContext resourceExecutedContext, ResourceExecutedContext resourceExecutedContext,
IResourceFilter filter) IResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutedContext != null); Debug.Assert(resourceExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResourceExecutedImpl(diagnosticListener, resourceExecutedContext, filter);
}
}
private static void BeforeOnResourceExecutedImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted", "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted",
new new
{ {
@ -252,17 +351,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResourceExecuted( public static void AfterOnResourceExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResourceExecutedContext resourceExecutedContext, ResourceExecutedContext resourceExecutedContext,
IResourceFilter filter) IResourceFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resourceExecutedContext != null); Debug.Assert(resourceExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResourceExecutedImpl(diagnosticListener, resourceExecutedContext, filter);
}
}
private static void AfterOnResourceExecutedImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IResourceFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted", "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted",
new new
{ {
@ -274,17 +382,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnExceptionAsync( public static void BeforeOnExceptionAsync(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ExceptionContext exceptionContext, ExceptionContext exceptionContext,
IAsyncExceptionFilter filter) IAsyncExceptionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(exceptionContext != null); Debug.Assert(exceptionContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnExceptionAsyncImpl(diagnosticListener, exceptionContext, filter);
}
}
private static void BeforeOnExceptionAsyncImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IAsyncExceptionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnException", "Microsoft.AspNetCore.Mvc.BeforeOnException",
new new
{ {
@ -296,17 +413,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnExceptionAsync( public static void AfterOnExceptionAsync(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ExceptionContext exceptionContext, ExceptionContext exceptionContext,
IAsyncExceptionFilter filter) IAsyncExceptionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(exceptionContext != null); Debug.Assert(exceptionContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnExceptionAsyncImpl(diagnosticListener, exceptionContext, filter);
}
}
private static void AfterOnExceptionAsyncImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IAsyncExceptionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnException", "Microsoft.AspNetCore.Mvc.AfterOnException",
new new
{ {
@ -318,17 +444,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnException( public static void BeforeOnException(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ExceptionContext exceptionContext, ExceptionContext exceptionContext,
IExceptionFilter filter) IExceptionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(exceptionContext != null); Debug.Assert(exceptionContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnExceptionImpl(diagnosticListener, exceptionContext, filter);
}
}
private static void BeforeOnExceptionImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IExceptionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnException", "Microsoft.AspNetCore.Mvc.BeforeOnException",
new new
{ {
@ -340,17 +475,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnException( public static void AfterOnException(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ExceptionContext exceptionContext, ExceptionContext exceptionContext,
IExceptionFilter filter) IExceptionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(exceptionContext != null); Debug.Assert(exceptionContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnExceptionImpl(diagnosticListener, exceptionContext, filter);
}
}
private static void AfterOnExceptionImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IExceptionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnException", "Microsoft.AspNetCore.Mvc.AfterOnException",
new new
{ {
@ -362,17 +506,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnActionExecution( public static void BeforeOnActionExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutingContext actionExecutingContext, ActionExecutingContext actionExecutingContext,
IAsyncActionFilter filter) IAsyncActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutingContext != null); Debug.Assert(actionExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnActionExecutionImpl(diagnosticListener, actionExecutingContext, filter);
}
}
private static void BeforeOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IAsyncActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnActionExecution", "Microsoft.AspNetCore.Mvc.BeforeOnActionExecution",
new new
{ {
@ -384,17 +537,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnActionExecution( public static void AfterOnActionExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutedContext actionExecutedContext, ActionExecutedContext actionExecutedContext,
IAsyncActionFilter filter) IAsyncActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutedContext != null); Debug.Assert(actionExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnActionExecutionImpl(diagnosticListener, actionExecutedContext, filter);
}
}
private static void AfterOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnActionExecution", "Microsoft.AspNetCore.Mvc.AfterOnActionExecution",
new new
{ {
@ -406,17 +568,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnActionExecuting( public static void BeforeOnActionExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutingContext actionExecutingContext, ActionExecutingContext actionExecutingContext,
IActionFilter filter) IActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutingContext != null); Debug.Assert(actionExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnActionExecutingImpl(diagnosticListener, actionExecutingContext, filter);
}
}
private static void BeforeOnActionExecutingImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting", "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting",
new new
{ {
@ -428,17 +599,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnActionExecuting( public static void AfterOnActionExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutingContext actionExecutingContext, ActionExecutingContext actionExecutingContext,
IActionFilter filter) IActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutingContext != null); Debug.Assert(actionExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnActionExecutingImpl(diagnosticListener, actionExecutingContext, filter);
}
}
private static void AfterOnActionExecutingImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnActionExecuting", "Microsoft.AspNetCore.Mvc.AfterOnActionExecuting",
new new
{ {
@ -450,17 +630,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnActionExecuted( public static void BeforeOnActionExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutedContext actionExecutedContext, ActionExecutedContext actionExecutedContext,
IActionFilter filter) IActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutedContext != null); Debug.Assert(actionExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnActionExecutedImpl(diagnosticListener, actionExecutedContext, filter);
}
}
private static void BeforeOnActionExecutedImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted", "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted",
new new
{ {
@ -472,17 +661,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnActionExecuted( public static void AfterOnActionExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionExecutedContext actionExecutedContext, ActionExecutedContext actionExecutedContext,
IActionFilter filter) IActionFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionExecutedContext != null); Debug.Assert(actionExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnActionExecutedImpl(diagnosticListener, actionExecutedContext, filter);
}
}
private static void AfterOnActionExecutedImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IActionFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnActionExecuted", "Microsoft.AspNetCore.Mvc.AfterOnActionExecuted",
new new
{ {
@ -494,19 +692,28 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeActionMethod( public static void BeforeActionMethod(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
IDictionary<string, object> actionArguments, IDictionary<string, object> actionArguments,
object controller) object controller)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(actionArguments != null); Debug.Assert(actionArguments != null);
Debug.Assert(controller != null); Debug.Assert(controller != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionMethod")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeActionMethodImpl(diagnosticListener, actionContext, actionArguments, controller);
}
}
private static void BeforeActionMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IDictionary<string, object> actionArguments, object controller)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionMethod"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeActionMethod", "Microsoft.AspNetCore.Mvc.BeforeActionMethod",
new new
{ {
@ -518,20 +725,29 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterActionMethod( public static void AfterActionMethod(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
IDictionary<string, object> actionArguments, IDictionary<string, object> actionArguments,
object controller, object controller,
IActionResult result) IActionResult result)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(actionArguments != null); Debug.Assert(actionArguments != null);
Debug.Assert(controller != null); Debug.Assert(controller != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionMethod")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterActionMethodImpl(diagnosticListener, actionContext, actionArguments, controller, result);
}
}
private static void AfterActionMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IDictionary<string, object> actionArguments, object controller, IActionResult result)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionMethod"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterActionMethod", "Microsoft.AspNetCore.Mvc.AfterActionMethod",
new new
{ {
@ -544,17 +760,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResultExecution( public static void BeforeOnResultExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutingContext resultExecutingContext, ResultExecutingContext resultExecutingContext,
IAsyncResultFilter filter) IAsyncResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutingContext != null); Debug.Assert(resultExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResultExecutionImpl(diagnosticListener, resultExecutingContext, filter);
}
}
private static void BeforeOnResultExecutionImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IAsyncResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResultExecution", "Microsoft.AspNetCore.Mvc.BeforeOnResultExecution",
new new
{ {
@ -566,17 +791,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResultExecution( public static void AfterOnResultExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutedContext resultExecutedContext, ResultExecutedContext resultExecutedContext,
IAsyncResultFilter filter) IAsyncResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutedContext != null); Debug.Assert(resultExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResultExecutionImpl(diagnosticListener, resultExecutedContext, filter);
}
}
private static void AfterOnResultExecutionImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IAsyncResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResultExecution", "Microsoft.AspNetCore.Mvc.AfterOnResultExecution",
new new
{ {
@ -588,17 +822,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResultExecuting( public static void BeforeOnResultExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutingContext resultExecutingContext, ResultExecutingContext resultExecutingContext,
IResultFilter filter) IResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutingContext != null); Debug.Assert(resultExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResultExecutingImpl(diagnosticListener, resultExecutingContext, filter);
}
}
private static void BeforeOnResultExecutingImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting", "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting",
new new
{ {
@ -610,17 +853,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResultExecuting( public static void AfterOnResultExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutingContext resultExecutingContext, ResultExecutingContext resultExecutingContext,
IResultFilter filter) IResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutingContext != null); Debug.Assert(resultExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResultExecutingImpl(diagnosticListener, resultExecutingContext, filter);
}
}
private static void AfterOnResultExecutingImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResultExecuting", "Microsoft.AspNetCore.Mvc.AfterOnResultExecuting",
new new
{ {
@ -632,17 +884,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeOnResultExecuted( public static void BeforeOnResultExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutedContext resultExecutedContext, ResultExecutedContext resultExecutedContext,
IResultFilter filter) IResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutedContext != null); Debug.Assert(resultExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnResultExecutedImpl(diagnosticListener, resultExecutedContext, filter);
}
}
private static void BeforeOnResultExecutedImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted", "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted",
new new
{ {
@ -654,17 +915,26 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void AfterOnResultExecuted( public static void AfterOnResultExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ResultExecutedContext resultExecutedContext, ResultExecutedContext resultExecutedContext,
IResultFilter filter) IResultFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(resultExecutedContext != null); Debug.Assert(resultExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnResultExecutedImpl(diagnosticListener, resultExecutedContext, filter);
}
}
private static void AfterOnResultExecutedImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IResultFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnResultExecuted", "Microsoft.AspNetCore.Mvc.AfterOnResultExecuted",
new new
{ {
@ -676,34 +946,52 @@ namespace Microsoft.AspNetCore.Mvc
} }
public static void BeforeActionResult( public static void BeforeActionResult(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
IActionResult result) IActionResult result)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(result != null); Debug.Assert(result != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionResult")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeActionResultImpl(diagnosticListener, actionContext, result);
}
}
private static void BeforeActionResultImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IActionResult result)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionResult"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeActionResult", "Microsoft.AspNetCore.Mvc.BeforeActionResult",
new { actionContext = actionContext, result = result }); new { actionContext = actionContext, result = result });
} }
} }
public static void AfterActionResult( public static void AfterActionResult(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
IActionResult result) IActionResult result)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(result != null); Debug.Assert(result != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionResult")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterActionResultImpl(diagnosticListener, actionContext, result);
}
}
private static void AfterActionResultImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IActionResult result)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionResult"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterActionResult", "Microsoft.AspNetCore.Mvc.AfterActionResult",
new { actionContext = actionContext, result = result }); new { actionContext = actionContext, result = result });
} }

View File

@ -18,21 +18,21 @@ namespace Microsoft.AspNetCore.Mvc.Routing
private readonly IActionInvokerFactory _actionInvokerFactory; private readonly IActionInvokerFactory _actionInvokerFactory;
private readonly IActionSelector _actionSelector; private readonly IActionSelector _actionSelector;
private readonly ILogger _logger; private readonly ILogger _logger;
private DiagnosticSource _diagnosticSource; private DiagnosticListener _diagnosticListener;
public MvcAttributeRouteHandler( public MvcAttributeRouteHandler(
IActionInvokerFactory actionInvokerFactory, IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector, IActionSelector actionSelector,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
: this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null) : this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor: null)
{ {
} }
public MvcAttributeRouteHandler( public MvcAttributeRouteHandler(
IActionInvokerFactory actionInvokerFactory, IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector, IActionSelector actionSelector,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IActionContextAccessor actionContextAccessor) IActionContextAccessor actionContextAccessor)
{ {
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
_actionInvokerFactory = actionInvokerFactory; _actionInvokerFactory = actionInvokerFactory;
_actionSelector = actionSelector; _actionSelector = actionSelector;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<MvcAttributeRouteHandler>(); _logger = loggerFactory.CreateLogger<MvcAttributeRouteHandler>();
} }

View File

@ -17,21 +17,21 @@ namespace Microsoft.AspNetCore.Mvc.Routing
private readonly IActionInvokerFactory _actionInvokerFactory; private readonly IActionInvokerFactory _actionInvokerFactory;
private readonly IActionSelector _actionSelector; private readonly IActionSelector _actionSelector;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
public MvcRouteHandler( public MvcRouteHandler(
IActionInvokerFactory actionInvokerFactory, IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector, IActionSelector actionSelector,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
: this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null) : this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor: null)
{ {
} }
public MvcRouteHandler( public MvcRouteHandler(
IActionInvokerFactory actionInvokerFactory, IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector, IActionSelector actionSelector,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IActionContextAccessor actionContextAccessor) IActionContextAccessor actionContextAccessor)
{ {
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
_actionInvokerFactory = actionInvokerFactory; _actionInvokerFactory = actionInvokerFactory;
_actionSelector = actionSelector; _actionSelector = actionSelector;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<MvcRouteHandler>(); _logger = loggerFactory.CreateLogger<MvcRouteHandler>();
} }

View File

@ -174,9 +174,9 @@ namespace Microsoft.Extensions.DependencyInjection
var optionsAccessor = s.GetRequiredService<IOptions<RazorViewEngineOptions>>(); var optionsAccessor = s.GetRequiredService<IOptions<RazorViewEngineOptions>>();
var razorFileSystem = s.GetRequiredService<RazorProjectFileSystem>(); var razorFileSystem = s.GetRequiredService<RazorProjectFileSystem>();
var loggerFactory = s.GetRequiredService<ILoggerFactory>(); var loggerFactory = s.GetRequiredService<ILoggerFactory>();
var diagnosticSource = s.GetRequiredService<DiagnosticSource>(); var diagnosticListener = s.GetRequiredService<DiagnosticListener>();
var viewEngine = new RazorViewEngine(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorFileSystem, loggerFactory, diagnosticSource); var viewEngine = new RazorViewEngine(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorFileSystem, loggerFactory, diagnosticListener);
return viewEngine; return viewEngine;
}); });
services.TryAddSingleton<IViewCompilerProvider, RazorViewCompilerProvider>(); services.TryAddSingleton<IViewCompilerProvider, RazorViewCompilerProvider>();

View File

@ -9,13 +9,25 @@ namespace Microsoft.AspNetCore.Mvc.Razor
internal static class MvcRazorDiagnosticSourceExtensions internal static class MvcRazorDiagnosticSourceExtensions
{ {
public static void BeforeViewPage( public static void BeforeViewPage(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
IRazorPage page, IRazorPage page,
ViewContext viewContext) ViewContext viewContext)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeViewPageImpl(diagnosticListener, page, viewContext);
}
}
private static void BeforeViewPageImpl(
this DiagnosticListener diagnosticListener,
IRazorPage page,
ViewContext viewContext)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage", "Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage",
new new
{ {
@ -28,13 +40,25 @@ namespace Microsoft.AspNetCore.Mvc.Razor
} }
public static void AfterViewPage( public static void AfterViewPage(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
IRazorPage page, IRazorPage page,
ViewContext viewContext) ViewContext viewContext)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterViewPageImpl(diagnosticListener, page, viewContext);
}
}
private static void AfterViewPageImpl(
this DiagnosticListener diagnosticListener,
IRazorPage page,
ViewContext viewContext)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.Razor.AfterViewPage", "Microsoft.AspNetCore.Mvc.Razor.AfterViewPage",
new new
{ {

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
private readonly IRazorViewEngine _viewEngine; private readonly IRazorViewEngine _viewEngine;
private readonly IRazorPageActivator _pageActivator; private readonly IRazorPageActivator _pageActivator;
private readonly HtmlEncoder _htmlEncoder; private readonly HtmlEncoder _htmlEncoder;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
private IViewBufferScope _bufferScope; private IViewBufferScope _bufferScope;
/// <summary> /// <summary>
@ -35,14 +35,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor
/// </param> /// </param>
/// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param> /// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param>
/// <param name="htmlEncoder">The HTML encoder.</param> /// <param name="htmlEncoder">The HTML encoder.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticListener"/>.</param>
public RazorView( public RazorView(
IRazorViewEngine viewEngine, IRazorViewEngine viewEngine,
IRazorPageActivator pageActivator, IRazorPageActivator pageActivator,
IReadOnlyList<IRazorPage> viewStartPages, IReadOnlyList<IRazorPage> viewStartPages,
IRazorPage razorPage, IRazorPage razorPage,
HtmlEncoder htmlEncoder, HtmlEncoder htmlEncoder,
DiagnosticSource diagnosticSource) DiagnosticListener diagnosticListener)
{ {
if (viewEngine == null) if (viewEngine == null)
{ {
@ -69,9 +69,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor
throw new ArgumentNullException(nameof(htmlEncoder)); throw new ArgumentNullException(nameof(htmlEncoder));
} }
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
throw new ArgumentNullException(nameof(diagnosticSource)); throw new ArgumentNullException(nameof(diagnosticListener));
} }
_viewEngine = viewEngine; _viewEngine = viewEngine;
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
ViewStartPages = viewStartPages; ViewStartPages = viewStartPages;
RazorPage = razorPage; RazorPage = razorPage;
_htmlEncoder = htmlEncoder; _htmlEncoder = htmlEncoder;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
} }
/// <inheritdoc /> /// <inheritdoc />
@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
OnAfterPageActivated?.Invoke(page, context); OnAfterPageActivated?.Invoke(page, context);
_diagnosticSource.BeforeViewPage(page, context); _diagnosticListener.BeforeViewPage(page, context);
try try
{ {
@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
} }
finally finally
{ {
_diagnosticSource.AfterViewPage(page, context); _diagnosticListener.AfterViewPage(page, context);
} }
} }

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly RazorViewEngineOptions _options; private readonly RazorViewEngineOptions _options;
private readonly RazorProject _razorFileSystem; private readonly RazorProject _razorFileSystem;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RazorViewEngine" />. /// Initializes a new instance of the <see cref="RazorViewEngine" />.
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
IOptions<RazorViewEngineOptions> optionsAccessor, IOptions<RazorViewEngineOptions> optionsAccessor,
RazorProject razorProject, RazorProject razorProject,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
DiagnosticSource diagnosticSource) DiagnosticListener diagnosticListener)
{ {
_options = optionsAccessor.Value; _options = optionsAccessor.Value;
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
_htmlEncoder = htmlEncoder; _htmlEncoder = htmlEncoder;
_logger = loggerFactory.CreateLogger<RazorViewEngine>(); _logger = loggerFactory.CreateLogger<RazorViewEngine>();
_razorFileSystem = razorProject; _razorFileSystem = razorProject;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); ViewLookupCache = new MemoryCache(new MemoryCacheOptions());
} }
@ -93,9 +93,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor
IOptions<RazorViewEngineOptions> optionsAccessor, IOptions<RazorViewEngineOptions> optionsAccessor,
RazorProjectFileSystem razorFileSystem, RazorProjectFileSystem razorFileSystem,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
DiagnosticSource diagnosticSource) DiagnosticListener diagnosticListener)
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
: this (pageFactory, pageActivator, htmlEncoder, optionsAccessor, (RazorProject)razorFileSystem, loggerFactory, diagnosticSource) : this (pageFactory, pageActivator, htmlEncoder, optionsAccessor, (RazorProject)razorFileSystem, loggerFactory, diagnosticListener)
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
{ {
} }
@ -498,7 +498,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
viewStarts[i] = viewStartItem.PageFactory(); viewStarts[i] = viewStartItem.PageFactory();
} }
var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder, _diagnosticSource); var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder, _diagnosticListener);
return ViewEngineResult.Found(viewName, view); return ViewEngineResult.Found(viewName, view);
} }

View File

@ -0,0 +1,17 @@
[
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine : Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider pageFactory, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions> optionsAccessor, Microsoft.AspNetCore.Razor.Language.RazorProject razorProject, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine : Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider pageFactory, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions> optionsAccessor, Microsoft.AspNetCore.Razor.Language.RazorProjectFileSystem razorFileSystem, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorView : Microsoft.AspNetCore.Mvc.ViewEngines.IView",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine viewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.Razor.IRazorPage> viewStartPages, Microsoft.AspNetCore.Mvc.Razor.IRazorPage razorPage, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, System.Diagnostics.DiagnosticSource diagnosticSource)",
"Kind": "Removal"
}
]

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IUrlHelperFactory urlHelperFactory, IUrlHelperFactory urlHelperFactory,
IJsonHelper jsonHelper, IJsonHelper jsonHelper,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
HtmlEncoder htmlEncoder, HtmlEncoder htmlEncoder,
IModelExpressionProvider modelExpressionProvider) IModelExpressionProvider modelExpressionProvider)
{ {
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
{ {
UrlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context), UrlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context),
JsonHelperAccessor = context => jsonHelper, JsonHelperAccessor = context => jsonHelper,
DiagnosticSourceAccessor = context => diagnosticSource, DiagnosticSourceAccessor = context => diagnosticListener,
HtmlEncoderAccessor = context => htmlEncoder, HtmlEncoderAccessor = context => htmlEncoder,
ModelExpressionProviderAccessor = context => modelExpressionProvider, ModelExpressionProviderAccessor = context => modelExpressionProvider,
}; };

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
public PageActionInvoker( public PageActionInvoker(
IPageHandlerMethodSelector handlerMethodSelector, IPageHandlerMethodSelector handlerMethodSelector,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILogger logger, ILogger logger,
IActionResultTypeMapper mapper, IActionResultTypeMapper mapper,
PageContext pageContext, PageContext pageContext,
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
ITempDataDictionaryFactory tempDataFactory, ITempDataDictionaryFactory tempDataFactory,
HtmlHelperOptions htmlHelperOptions) HtmlHelperOptions htmlHelperOptions)
: base( : base(
diagnosticSource, diagnosticListener,
logger, logger,
mapper, mapper,
pageContext, pageContext,
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
Debug.Assert(executor != null, "We should always find a executor for a handler"); Debug.Assert(executor != null, "We should always find a executor for a handler");
_diagnosticSource.BeforeHandlerMethod(_pageContext, handler, _arguments, _instance); _diagnosticListener.BeforeHandlerMethod(_pageContext, handler, _arguments, _instance);
_logger.ExecutingHandlerMethod(_pageContext, handler, arguments); _logger.ExecutingHandlerMethod(_pageContext, handler, arguments);
try try
@ -265,7 +265,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
} }
finally finally
{ {
_diagnosticSource.AfterHandlerMethod(_pageContext, handler, _arguments, _instance, _result); _diagnosticListener.AfterHandlerMethod(_pageContext, handler, _arguments, _instance, _result);
} }
} }
@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IAsyncPageFilter)state; var filter = (IAsyncPageFilter)state;
var handlerSelectedContext = _handlerSelectedContext; var handlerSelectedContext = _handlerSelectedContext;
_diagnosticSource.BeforeOnPageHandlerSelection(handlerSelectedContext, filter); _diagnosticListener.BeforeOnPageHandlerSelection(handlerSelectedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync), nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync),
@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IAsyncPageFilter)state; var filter = (IAsyncPageFilter)state;
_diagnosticSource.AfterOnPageHandlerSelection(_handlerSelectedContext, filter); _diagnosticListener.AfterOnPageHandlerSelection(_handlerSelectedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync), nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync),
@ -387,7 +387,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IPageFilter)state; var filter = (IPageFilter)state;
var handlerSelectedContext = _handlerSelectedContext; var handlerSelectedContext = _handlerSelectedContext;
_diagnosticSource.BeforeOnPageHandlerSelected(handlerSelectedContext, filter); _diagnosticListener.BeforeOnPageHandlerSelected(handlerSelectedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IPageFilter.OnPageHandlerSelected), nameof(IPageFilter.OnPageHandlerSelected),
@ -395,7 +395,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
filter.OnPageHandlerSelected(handlerSelectedContext); filter.OnPageHandlerSelected(handlerSelectedContext);
_diagnosticSource.AfterOnPageHandlerSelected(handlerSelectedContext, filter); _diagnosticListener.AfterOnPageHandlerSelected(handlerSelectedContext, filter);
goto case State.PageSelectHandlerNext; goto case State.PageSelectHandlerNext;
} }
@ -458,7 +458,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IAsyncPageFilter)state; var filter = (IAsyncPageFilter)state;
var handlerExecutingContext = _handlerExecutingContext; var handlerExecutingContext = _handlerExecutingContext;
_diagnosticSource.BeforeOnPageHandlerExecution(handlerExecutingContext, filter); _diagnosticListener.BeforeOnPageHandlerExecution(handlerExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync), nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync),
@ -497,7 +497,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
}; };
} }
_diagnosticSource.AfterOnPageHandlerExecution(_handlerExecutedContext, filter); _diagnosticListener.AfterOnPageHandlerExecution(_handlerExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync), nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync),
@ -514,7 +514,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IPageFilter)state; var filter = (IPageFilter)state;
var handlerExecutingContext = _handlerExecutingContext; var handlerExecutingContext = _handlerExecutingContext;
_diagnosticSource.BeforeOnPageHandlerExecuting(handlerExecutingContext, filter); _diagnosticListener.BeforeOnPageHandlerExecuting(handlerExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IPageFilter.OnPageHandlerExecuting), nameof(IPageFilter.OnPageHandlerExecuting),
@ -522,7 +522,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
filter.OnPageHandlerExecuting(handlerExecutingContext); filter.OnPageHandlerExecuting(handlerExecutingContext);
_diagnosticSource.AfterOnPageHandlerExecuting(handlerExecutingContext, filter); _diagnosticListener.AfterOnPageHandlerExecuting(handlerExecutingContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IPageFilter.OnPageHandlerExecuting), nameof(IPageFilter.OnPageHandlerExecuting),
@ -565,7 +565,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
var filter = (IPageFilter)state; var filter = (IPageFilter)state;
var handlerExecutedContext = _handlerExecutedContext; var handlerExecutedContext = _handlerExecutedContext;
_diagnosticSource.BeforeOnPageHandlerExecuted(handlerExecutedContext, filter); _diagnosticListener.BeforeOnPageHandlerExecuted(handlerExecutedContext, filter);
_logger.BeforeExecutingMethodOnFilter( _logger.BeforeExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IPageFilter.OnPageHandlerExecuted), nameof(IPageFilter.OnPageHandlerExecuted),
@ -573,7 +573,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
filter.OnPageHandlerExecuted(handlerExecutedContext); filter.OnPageHandlerExecuted(handlerExecutedContext);
_diagnosticSource.AfterOnPageHandlerExecuted(handlerExecutedContext, filter); _diagnosticListener.AfterOnPageHandlerExecuted(handlerExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter( _logger.AfterExecutingMethodOnFilter(
PageLoggerExtensions.PageFilter, PageLoggerExtensions.PageFilter,
nameof(IPageFilter.OnPageHandlerExecuted), nameof(IPageFilter.OnPageHandlerExecuted),

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
private readonly HtmlHelperOptions _htmlHelperOptions; private readonly HtmlHelperOptions _htmlHelperOptions;
private readonly IPageHandlerMethodSelector _selector; private readonly IPageHandlerMethodSelector _selector;
private readonly RazorProjectFileSystem _razorFileSystem; private readonly RazorProjectFileSystem _razorFileSystem;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
private readonly ILogger<PageActionInvoker> _logger; private readonly ILogger<PageActionInvoker> _logger;
private readonly IActionResultTypeMapper _mapper; private readonly IActionResultTypeMapper _mapper;
private volatile InnerCache _currentCache; private volatile InnerCache _currentCache;
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
IOptions<HtmlHelperOptions> htmlHelperOptions, IOptions<HtmlHelperOptions> htmlHelperOptions,
IPageHandlerMethodSelector selector, IPageHandlerMethodSelector selector,
RazorProjectFileSystem razorFileSystem, RazorProjectFileSystem razorFileSystem,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IActionResultTypeMapper mapper) IActionResultTypeMapper mapper)
{ {
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
_htmlHelperOptions = htmlHelperOptions.Value; _htmlHelperOptions = htmlHelperOptions.Value;
_selector = selector; _selector = selector;
_razorFileSystem = razorFileSystem; _razorFileSystem = razorFileSystem;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<PageActionInvoker>(); _logger = loggerFactory.CreateLogger<PageActionInvoker>();
_mapper = mapper; _mapper = mapper;
} }
@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
return new PageActionInvoker( return new PageActionInvoker(
_selector, _selector,
_diagnosticSource, _diagnosticListener,
_logger, _logger,
_mapper, _mapper,
pageContext, pageContext,

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
{ {
private readonly IRazorViewEngine _razorViewEngine; private readonly IRazorViewEngine _razorViewEngine;
private readonly IRazorPageActivator _razorPageActivator; private readonly IRazorPageActivator _razorPageActivator;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
private readonly HtmlEncoder _htmlEncoder; private readonly HtmlEncoder _htmlEncoder;
/// <summary> /// <summary>
@ -30,21 +30,21 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
/// <param name="compositeViewEngine">The <see cref="ICompositeViewEngine"/>.</param> /// <param name="compositeViewEngine">The <see cref="ICompositeViewEngine"/>.</param>
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param> /// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
/// <param name="razorPageActivator">The <see cref="IRazorPageActivator"/>.</param> /// <param name="razorPageActivator">The <see cref="IRazorPageActivator"/>.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticListener"/>.</param>
/// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param> /// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
public PageResultExecutor( public PageResultExecutor(
IHttpResponseStreamWriterFactory writerFactory, IHttpResponseStreamWriterFactory writerFactory,
ICompositeViewEngine compositeViewEngine, ICompositeViewEngine compositeViewEngine,
IRazorViewEngine razorViewEngine, IRazorViewEngine razorViewEngine,
IRazorPageActivator razorPageActivator, IRazorPageActivator razorPageActivator,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
HtmlEncoder htmlEncoder) HtmlEncoder htmlEncoder)
: base(writerFactory, compositeViewEngine, diagnosticSource) : base(writerFactory, compositeViewEngine, diagnosticListener)
{ {
_razorViewEngine = razorViewEngine; _razorViewEngine = razorViewEngine;
_htmlEncoder = htmlEncoder; _htmlEncoder = htmlEncoder;
_razorPageActivator = razorPageActivator; _razorPageActivator = razorPageActivator;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
} }
/// <summary> /// <summary>
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
viewStarts, viewStarts,
pageAdapter, pageAdapter,
_htmlEncoder, _htmlEncoder,
_diagnosticSource) _diagnosticListener)
{ {
OnAfterPageActivated = (page, currentViewContext) => OnAfterPageActivated = (page, currentViewContext) =>
{ {

View File

@ -11,21 +11,30 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
internal static class MvcRazorPagesDiagnosticSourceExtensions internal static class MvcRazorPagesDiagnosticSourceExtensions
{ {
public static void BeforeHandlerMethod( public static void BeforeHandlerMethod(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
HandlerMethodDescriptor handlerMethodDescriptor, HandlerMethodDescriptor handlerMethodDescriptor,
IDictionary<string, object> arguments, IDictionary<string, object> arguments,
object instance) object instance)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(handlerMethodDescriptor != null); Debug.Assert(handlerMethodDescriptor != null);
Debug.Assert(arguments != null); Debug.Assert(arguments != null);
Debug.Assert(instance != null); Debug.Assert(instance != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeHandlerMethod")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeHandlerMethodImpl(diagnosticListener, actionContext, handlerMethodDescriptor, arguments, instance);
}
}
private static void BeforeHandlerMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, HandlerMethodDescriptor handlerMethodDescriptor, IDictionary<string, object> arguments, object instance)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeHandlerMethod"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeHandlerMethod", "Microsoft.AspNetCore.Mvc.BeforeHandlerMethod",
new new
{ {
@ -38,22 +47,31 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterHandlerMethod( public static void AfterHandlerMethod(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
HandlerMethodDescriptor handlerMethodDescriptor, HandlerMethodDescriptor handlerMethodDescriptor,
IDictionary<string, object> arguments, IDictionary<string, object> arguments,
object instance, object instance,
IActionResult result) IActionResult result)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(actionContext != null); Debug.Assert(actionContext != null);
Debug.Assert(handlerMethodDescriptor != null); Debug.Assert(handlerMethodDescriptor != null);
Debug.Assert(arguments != null); Debug.Assert(arguments != null);
Debug.Assert(instance != null); Debug.Assert(instance != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterHandlerMethod")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterHandlerMethodImpl(diagnosticListener, actionContext, handlerMethodDescriptor, arguments, instance, result);
}
}
private static void AfterHandlerMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, HandlerMethodDescriptor handlerMethodDescriptor, IDictionary<string, object> arguments, object instance, IActionResult result)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterHandlerMethod"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterHandlerMethod", "Microsoft.AspNetCore.Mvc.AfterHandlerMethod",
new new
{ {
@ -65,19 +83,28 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}); });
} }
} }
public static void BeforeOnPageHandlerExecution( public static void BeforeOnPageHandlerExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutingContext handlerExecutionContext, PageHandlerExecutingContext handlerExecutionContext,
IAsyncPageFilter filter) IAsyncPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutionContext != null); Debug.Assert(handlerExecutionContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnPageHandlerExecutionImpl(diagnosticListener, handlerExecutionContext, filter);
}
}
private static void BeforeOnPageHandlerExecutionImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutionContext, IAsyncPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution", "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution",
new new
{ {
@ -89,17 +116,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterOnPageHandlerExecution( public static void AfterOnPageHandlerExecution(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutedContext handlerExecutedContext, PageHandlerExecutedContext handlerExecutedContext,
IAsyncPageFilter filter) IAsyncPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutedContext != null); Debug.Assert(handlerExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnPageHandlerExecutionImpl(diagnosticListener, handlerExecutedContext, filter);
}
}
private static void AfterOnPageHandlerExecutionImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IAsyncPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution", "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution",
new new
{ {
@ -111,17 +147,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void BeforeOnPageHandlerExecuting( public static void BeforeOnPageHandlerExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutingContext handlerExecutingContext, PageHandlerExecutingContext handlerExecutingContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutingContext != null); Debug.Assert(handlerExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnPageHandlerExecutingImpl(diagnosticListener, handlerExecutingContext, filter);
}
}
private static void BeforeOnPageHandlerExecutingImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutingContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting", "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting",
new new
{ {
@ -133,17 +178,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterOnPageHandlerExecuting( public static void AfterOnPageHandlerExecuting(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutingContext handlerExecutingContext, PageHandlerExecutingContext handlerExecutingContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutingContext != null); Debug.Assert(handlerExecutingContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnPageHandlerExecutingImpl(diagnosticListener, handlerExecutingContext, filter);
}
}
private static void AfterOnPageHandlerExecutingImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutingContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting", "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting",
new new
{ {
@ -155,17 +209,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void BeforeOnPageHandlerExecuted( public static void BeforeOnPageHandlerExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutedContext handlerExecutedContext, PageHandlerExecutedContext handlerExecutedContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutedContext != null); Debug.Assert(handlerExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnPageHandlerExecutedImpl(diagnosticListener, handlerExecutedContext, filter);
}
}
private static void BeforeOnPageHandlerExecutedImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted", "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted",
new new
{ {
@ -177,17 +240,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterOnPageHandlerExecuted( public static void AfterOnPageHandlerExecuted(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerExecutedContext handlerExecutedContext, PageHandlerExecutedContext handlerExecutedContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerExecutedContext != null); Debug.Assert(handlerExecutedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnPageHandlerExecutedImpl(diagnosticListener, handlerExecutedContext, filter);
}
}
private static void AfterOnPageHandlerExecutedImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted", "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted",
new new
{ {
@ -199,17 +271,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void BeforeOnPageHandlerSelection( public static void BeforeOnPageHandlerSelection(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerSelectedContext handlerSelectedContext, PageHandlerSelectedContext handlerSelectedContext,
IAsyncPageFilter filter) IAsyncPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerSelectedContext != null); Debug.Assert(handlerSelectedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnPageHandlerSelectionImpl(diagnosticListener, handlerSelectedContext, filter);
}
}
private static void BeforeOnPageHandlerSelectionImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IAsyncPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection", "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection",
new new
{ {
@ -221,17 +302,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterOnPageHandlerSelection( public static void AfterOnPageHandlerSelection(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerSelectedContext handlerSelectedContext, PageHandlerSelectedContext handlerSelectedContext,
IAsyncPageFilter filter) IAsyncPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerSelectedContext != null); Debug.Assert(handlerSelectedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnPageHandlerSelectionImpl(diagnosticListener, handlerSelectedContext, filter);
}
}
private static void AfterOnPageHandlerSelectionImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IAsyncPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection", "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection",
new new
{ {
@ -243,17 +333,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void BeforeOnPageHandlerSelected( public static void BeforeOnPageHandlerSelected(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerSelectedContext handlerSelectedContext, PageHandlerSelectedContext handlerSelectedContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerSelectedContext != null); Debug.Assert(handlerSelectedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeOnPageHandlerSelectedImpl(diagnosticListener, handlerSelectedContext, filter);
}
}
private static void BeforeOnPageHandlerSelectedImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected", "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected",
new new
{ {
@ -265,17 +364,26 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
} }
public static void AfterOnPageHandlerSelected( public static void AfterOnPageHandlerSelected(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
PageHandlerSelectedContext handlerSelectedContext, PageHandlerSelectedContext handlerSelectedContext,
IPageFilter filter) IPageFilter filter)
{ {
Debug.Assert(diagnosticSource != null); Debug.Assert(diagnosticListener != null);
Debug.Assert(handlerSelectedContext != null); Debug.Assert(handlerSelectedContext != null);
Debug.Assert(filter != null); Debug.Assert(filter != null);
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterOnPageHandlerSelectedImpl(diagnosticListener, handlerSelectedContext, filter);
}
}
private static void AfterOnPageHandlerSelectedImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IPageFilter filter)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected", "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected",
new new
{ {

View File

@ -0,0 +1,12 @@
[
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageResultExecutor : Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine compositeViewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine razorViewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator razorPageActivator, System.Diagnostics.DiagnosticSource diagnosticSource, System.Text.Encodings.Web.HtmlEncoder htmlEncoder)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageFactoryProvider : Microsoft.AspNetCore.Mvc.RazorPages.IPageFactoryProvider",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.RazorPages.IPageActivatorProvider pageActivator, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory urlHelperFactory, Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper jsonHelper, System.Diagnostics.DiagnosticSource diagnosticSource, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider modelExpressionProvider)",
"Kind": "Removal"
}
]

View File

@ -12,13 +12,22 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
internal static class MvcViewFeaturesDiagnosticSourceExtensions internal static class MvcViewFeaturesDiagnosticSourceExtensions
{ {
public static void BeforeViewComponent( public static void BeforeViewComponent(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ViewComponentContext context, ViewComponentContext context,
object viewComponent) object viewComponent)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeViewComponent")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeViewComponentImpl(diagnosticListener, context, viewComponent);
}
}
private static void BeforeViewComponentImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, object viewComponent)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeViewComponent"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeViewComponent", "Microsoft.AspNetCore.Mvc.BeforeViewComponent",
new new
{ {
@ -30,14 +39,23 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
public static void AfterViewComponent( public static void AfterViewComponent(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ViewComponentContext context, ViewComponentContext context,
IViewComponentResult result, IViewComponentResult result,
object viewComponent) object viewComponent)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterViewComponent")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterViewComponentImpl(diagnosticListener, context, result, viewComponent);
}
}
private static void AfterViewComponentImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, IViewComponentResult result, object viewComponent)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterViewComponent"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterViewComponent", "Microsoft.AspNetCore.Mvc.AfterViewComponent",
new new
{ {
@ -50,13 +68,22 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
public static void ViewComponentBeforeViewExecute( public static void ViewComponentBeforeViewExecute(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ViewComponentContext context, ViewComponentContext context,
IView view) IView view)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewComponentBeforeViewExecute")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( ViewComponentBeforeViewExecuteImpl(diagnosticListener, context, view);
}
}
private static void ViewComponentBeforeViewExecuteImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, IView view)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.ViewComponentBeforeViewExecute"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.ViewComponentBeforeViewExecute", "Microsoft.AspNetCore.Mvc.ViewComponentBeforeViewExecute",
new new
{ {
@ -68,13 +95,22 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
public static void ViewComponentAfterViewExecute( public static void ViewComponentAfterViewExecute(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ViewComponentContext context, ViewComponentContext context,
IView view) IView view)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewComponentAfterViewExecute")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( ViewComponentAfterViewExecuteImpl(diagnosticListener, context, view);
}
}
private static void ViewComponentAfterViewExecuteImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, IView view)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.ViewComponentAfterViewExecute"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.ViewComponentAfterViewExecute", "Microsoft.AspNetCore.Mvc.ViewComponentAfterViewExecute",
new new
{ {
@ -86,42 +122,69 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
public static void BeforeView( public static void BeforeView(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
IView view, IView view,
ViewContext viewContext) ViewContext viewContext)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeView")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( BeforeViewImpl(diagnosticListener, view, viewContext);
}
}
private static void BeforeViewImpl(DiagnosticListener diagnosticListener, IView view, ViewContext viewContext)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeView"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.BeforeView", "Microsoft.AspNetCore.Mvc.BeforeView",
new { view = view, viewContext = viewContext, }); new { view = view, viewContext = viewContext, });
} }
} }
public static void AfterView( public static void AfterView(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
IView view, IView view,
ViewContext viewContext) ViewContext viewContext)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterView")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( AfterViewImpl(diagnosticListener, view, viewContext);
}
}
private static void AfterViewImpl(DiagnosticListener diagnosticListener, IView view, ViewContext viewContext)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterView"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.AfterView", "Microsoft.AspNetCore.Mvc.AfterView",
new { view = view, viewContext = viewContext, }); new { view = view, viewContext = viewContext, });
} }
} }
public static void ViewFound( public static void ViewFound(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
bool isMainPage, bool isMainPage,
PartialViewResult viewResult, PartialViewResult viewResult,
string viewName, string viewName,
IView view) IView view)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewFound")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( ViewFoundImpl(diagnosticListener, actionContext, isMainPage, viewResult, viewName, view);
}
}
private static void ViewFoundImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, bool isMainPage, PartialViewResult viewResult, string viewName, IView view)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.ViewFound"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.ViewFound", "Microsoft.AspNetCore.Mvc.ViewFound",
new new
{ {
@ -135,16 +198,25 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
public static void ViewNotFound( public static void ViewNotFound(
this DiagnosticSource diagnosticSource, this DiagnosticListener diagnosticListener,
ActionContext actionContext, ActionContext actionContext,
bool isMainPage, bool isMainPage,
PartialViewResult viewResult, PartialViewResult viewResult,
string viewName, string viewName,
IEnumerable<string> searchedLocations) IEnumerable<string> searchedLocations)
{ {
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewNotFound")) // Inlinable fast-path check if Diagnositcs is enabled
if (diagnosticListener.IsEnabled())
{ {
diagnosticSource.Write( ViewNotFoundImpl(diagnosticListener, actionContext, isMainPage, viewResult, viewName, searchedLocations);
}
}
private static void ViewNotFoundImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, bool isMainPage, PartialViewResult viewResult, string viewName, IEnumerable<string> searchedLocations)
{
if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.ViewNotFound"))
{
diagnosticListener.Write(
"Microsoft.AspNetCore.Mvc.ViewNotFound", "Microsoft.AspNetCore.Mvc.ViewNotFound",
new new
{ {

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param> /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param> /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param> /// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticListener"/>.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param> /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
public PartialViewResultExecutor( public PartialViewResultExecutor(
@ -38,10 +38,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
IHttpResponseStreamWriterFactory writerFactory, IHttpResponseStreamWriterFactory writerFactory,
ICompositeViewEngine viewEngine, ICompositeViewEngine viewEngine,
ITempDataDictionaryFactory tempDataFactory, ITempDataDictionaryFactory tempDataFactory,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IModelMetadataProvider modelMetadataProvider) IModelMetadataProvider modelMetadataProvider)
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource, modelMetadataProvider) : base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticListener, modelMetadataProvider)
{ {
if (loggerFactory == null) if (loggerFactory == null)
{ {

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
{ {
private readonly IViewComponentFactory _viewComponentFactory; private readonly IViewComponentFactory _viewComponentFactory;
private readonly ViewComponentInvokerCache _viewComponentInvokerCache; private readonly ViewComponentInvokerCache _viewComponentInvokerCache;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
private readonly ILogger _logger; private readonly ILogger _logger;
/// <summary> /// <summary>
@ -27,12 +27,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
/// </summary> /// </summary>
/// <param name="viewComponentFactory">The <see cref="IViewComponentFactory"/>.</param> /// <param name="viewComponentFactory">The <see cref="IViewComponentFactory"/>.</param>
/// <param name="viewComponentInvokerCache">The <see cref="ViewComponentInvokerCache"/>.</param> /// <param name="viewComponentInvokerCache">The <see cref="ViewComponentInvokerCache"/>.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticListener"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param> /// <param name="logger">The <see cref="ILogger"/>.</param>
public DefaultViewComponentInvoker( public DefaultViewComponentInvoker(
IViewComponentFactory viewComponentFactory, IViewComponentFactory viewComponentFactory,
ViewComponentInvokerCache viewComponentInvokerCache, ViewComponentInvokerCache viewComponentInvokerCache,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILogger logger) ILogger logger)
{ {
if (viewComponentFactory == null) if (viewComponentFactory == null)
@ -45,9 +45,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
throw new ArgumentNullException(nameof(viewComponentInvokerCache)); throw new ArgumentNullException(nameof(viewComponentInvokerCache));
} }
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
throw new ArgumentNullException(nameof(diagnosticSource)); throw new ArgumentNullException(nameof(diagnosticListener));
} }
if (logger == null) if (logger == null)
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
_viewComponentFactory = viewComponentFactory; _viewComponentFactory = viewComponentFactory;
_viewComponentInvokerCache = viewComponentInvokerCache; _viewComponentInvokerCache = viewComponentInvokerCache;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_logger = logger; _logger = logger;
} }
@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
{ {
var arguments = PrepareArguments(context.Arguments, executor); var arguments = PrepareArguments(context.Arguments, executor);
_diagnosticSource.BeforeViewComponent(context, component); _diagnosticListener.BeforeViewComponent(context, component);
_logger.ViewComponentExecuting(context, arguments); _logger.ViewComponentExecuting(context, arguments);
var stopwatch = ValueStopwatch.StartNew(); var stopwatch = ValueStopwatch.StartNew();
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
var viewComponentResult = CoerceToViewComponentResult(resultAsObject); var viewComponentResult = CoerceToViewComponentResult(resultAsObject);
_logger.ViewComponentExecuted(context, stopwatch.GetElapsedTime(), viewComponentResult); _logger.ViewComponentExecuted(context, stopwatch.GetElapsedTime(), viewComponentResult);
_diagnosticSource.AfterViewComponent(context, viewComponentResult, component); _diagnosticListener.AfterViewComponent(context, viewComponentResult, component);
_viewComponentFactory.ReleaseViewComponent(context, component); _viewComponentFactory.ReleaseViewComponent(context, component);
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
{ {
var arguments = PrepareArguments(context.Arguments, executor); var arguments = PrepareArguments(context.Arguments, executor);
_diagnosticSource.BeforeViewComponent(context, component); _diagnosticListener.BeforeViewComponent(context, component);
_logger.ViewComponentExecuting(context, arguments); _logger.ViewComponentExecuting(context, arguments);
var stopwatch = ValueStopwatch.StartNew(); var stopwatch = ValueStopwatch.StartNew();
@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
var viewComponentResult = CoerceToViewComponentResult(result); var viewComponentResult = CoerceToViewComponentResult(result);
_logger.ViewComponentExecuted(context, stopwatch.GetElapsedTime(), viewComponentResult); _logger.ViewComponentExecuted(context, stopwatch.GetElapsedTime(), viewComponentResult);
_diagnosticSource.AfterViewComponent(context, viewComponentResult, component); _diagnosticListener.AfterViewComponent(context, viewComponentResult, component);
_viewComponentFactory.ReleaseViewComponent(context, component); _viewComponentFactory.ReleaseViewComponent(context, component);

View File

@ -12,12 +12,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
private readonly IViewComponentFactory _viewComponentFactory; private readonly IViewComponentFactory _viewComponentFactory;
private readonly ViewComponentInvokerCache _viewComponentInvokerCache; private readonly ViewComponentInvokerCache _viewComponentInvokerCache;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticListener _diagnosticListener;
public DefaultViewComponentInvokerFactory( public DefaultViewComponentInvokerFactory(
IViewComponentFactory viewComponentFactory, IViewComponentFactory viewComponentFactory,
ViewComponentInvokerCache viewComponentInvokerCache, ViewComponentInvokerCache viewComponentInvokerCache,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
{ {
if (viewComponentFactory == null) if (viewComponentFactory == null)
@ -30,9 +30,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
throw new ArgumentNullException(nameof(viewComponentInvokerCache)); throw new ArgumentNullException(nameof(viewComponentInvokerCache));
} }
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
throw new ArgumentNullException(nameof(diagnosticSource)); throw new ArgumentNullException(nameof(diagnosticListener));
} }
if (loggerFactory == null) if (loggerFactory == null)
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
} }
_viewComponentFactory = viewComponentFactory; _viewComponentFactory = viewComponentFactory;
_diagnosticSource = diagnosticSource; _diagnosticListener = diagnosticListener;
_viewComponentInvokerCache = viewComponentInvokerCache; _viewComponentInvokerCache = viewComponentInvokerCache;
_logger = loggerFactory.CreateLogger<DefaultViewComponentInvoker>(); _logger = loggerFactory.CreateLogger<DefaultViewComponentInvoker>();
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
return new DefaultViewComponentInvoker( return new DefaultViewComponentInvoker(
_viewComponentFactory, _viewComponentFactory,
_viewComponentInvokerCache, _viewComponentInvokerCache,
_diagnosticSource, _diagnosticListener,
_logger); _logger);
} }
} }

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
private const string ViewPathFormat = "Components/{0}/{1}"; private const string ViewPathFormat = "Components/{0}/{1}";
private const string DefaultViewName = "Default"; private const string DefaultViewName = "Default";
private DiagnosticSource _diagnosticSource; private DiagnosticListener _diagnosticListener;
/// <summary> /// <summary>
/// Gets or sets the view name. /// Gets or sets the view name.
@ -115,12 +115,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
var view = result.EnsureSuccessful(originalLocations).View; var view = result.EnsureSuccessful(originalLocations).View;
using (view as IDisposable) using (view as IDisposable)
{ {
if (_diagnosticSource == null) if (_diagnosticListener == null)
{ {
_diagnosticSource = viewContext.HttpContext.RequestServices.GetRequiredService<DiagnosticSource>(); _diagnosticListener = viewContext.HttpContext.RequestServices.GetRequiredService<DiagnosticListener>();
} }
_diagnosticSource.ViewComponentBeforeViewExecute(context, view); _diagnosticListener.ViewComponentBeforeViewExecute(context, view);
var childViewContext = new ViewContext( var childViewContext = new ViewContext(
viewContext, viewContext,
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
context.Writer); context.Writer);
await view.RenderAsync(childViewContext); await view.RenderAsync(childViewContext);
_diagnosticSource.ViewComponentAfterViewExecute(context, view); _diagnosticListener.ViewComponentAfterViewExecute(context, view);
} }
} }

View File

@ -32,16 +32,16 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param> /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param> /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param> /// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticSource"/>.</param>
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider" />.</param> /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider" />.</param>
public ViewExecutor( public ViewExecutor(
IOptions<MvcViewOptions> viewOptions, IOptions<MvcViewOptions> viewOptions,
IHttpResponseStreamWriterFactory writerFactory, IHttpResponseStreamWriterFactory writerFactory,
ICompositeViewEngine viewEngine, ICompositeViewEngine viewEngine,
ITempDataDictionaryFactory tempDataFactory, ITempDataDictionaryFactory tempDataFactory,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
IModelMetadataProvider modelMetadataProvider) IModelMetadataProvider modelMetadataProvider)
: this(writerFactory, viewEngine, diagnosticSource) : this(writerFactory, viewEngine, diagnosticListener)
{ {
if (viewOptions == null) if (viewOptions == null)
{ {
@ -53,9 +53,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
throw new ArgumentNullException(nameof(tempDataFactory)); throw new ArgumentNullException(nameof(tempDataFactory));
} }
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
throw new ArgumentNullException(nameof(diagnosticSource)); throw new ArgumentNullException(nameof(diagnosticListener));
} }
ViewOptions = viewOptions.Value; ViewOptions = viewOptions.Value;
@ -68,11 +68,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// </summary> /// </summary>
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param> /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param> /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
/// <param name="diagnosticSource">The <see cref="System.Diagnostics.DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="System.Diagnostics.DiagnosticListener"/>.</param>
protected ViewExecutor( protected ViewExecutor(
IHttpResponseStreamWriterFactory writerFactory, IHttpResponseStreamWriterFactory writerFactory,
ICompositeViewEngine viewEngine, ICompositeViewEngine viewEngine,
DiagnosticSource diagnosticSource) DiagnosticListener diagnosticListener)
{ {
if (writerFactory == null) if (writerFactory == null)
{ {
@ -84,20 +84,20 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
throw new ArgumentNullException(nameof(viewEngine)); throw new ArgumentNullException(nameof(viewEngine));
} }
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
throw new ArgumentNullException(nameof(diagnosticSource)); throw new ArgumentNullException(nameof(diagnosticListener));
} }
WriterFactory = writerFactory; WriterFactory = writerFactory;
ViewEngine = viewEngine; ViewEngine = viewEngine;
DiagnosticSource = diagnosticSource; DiagnosticSource = diagnosticListener;
} }
/// <summary> /// <summary>
/// Gets the <see cref="DiagnosticSource"/>. /// Gets the <see cref="DiagnosticSource"/>.
/// </summary> /// </summary>
protected DiagnosticSource DiagnosticSource { get; } protected DiagnosticListener DiagnosticSource { get; }
/// <summary> /// <summary>
/// Gets the <see cref="ITempDataDictionaryFactory"/>. /// Gets the <see cref="ITempDataDictionaryFactory"/>.

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param> /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param> /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
/// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param> /// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param> /// <param name="diagnosticListener">The <see cref="DiagnosticListener"/>.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param> /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
public ViewResultExecutor( public ViewResultExecutor(
@ -38,10 +38,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
IHttpResponseStreamWriterFactory writerFactory, IHttpResponseStreamWriterFactory writerFactory,
ICompositeViewEngine viewEngine, ICompositeViewEngine viewEngine,
ITempDataDictionaryFactory tempDataFactory, ITempDataDictionaryFactory tempDataFactory,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IModelMetadataProvider modelMetadataProvider) IModelMetadataProvider modelMetadataProvider)
: base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource, modelMetadataProvider) : base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticListener, modelMetadataProvider)
{ {
if (loggerFactory == null) if (loggerFactory == null)
{ {
@ -107,6 +107,25 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
} }
} }
if (DiagnosticSource.IsEnabled())
{
OutputDiagnostics(actionContext, viewResult, viewName, stopwatch, result);
}
if (result.Success)
{
Logger.ViewFound(result.View, stopwatch.GetElapsedTime());
}
else
{
Logger.ViewNotFound(viewName, result.SearchedLocations);
}
return result;
}
private void OutputDiagnostics(ActionContext actionContext, ViewResult viewResult, string viewName, ValueStopwatch stopwatch, ViewEngineResult result)
{
if (result.Success) if (result.Success)
{ {
if (DiagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewFound")) if (DiagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.ViewFound"))
@ -122,8 +141,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
view = result.View, view = result.View,
}); });
} }
Logger.ViewFound(result.View, stopwatch.GetElapsedTime());
} }
else else
{ {
@ -140,10 +157,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
searchedLocations = result.SearchedLocations searchedLocations = result.SearchedLocations
}); });
} }
Logger.ViewNotFound(viewName, result.SearchedLocations);
} }
return result;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -1,16 +1,30 @@
[ [
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.RemoteAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IClientModelValidator",
"Kind": "Removal"
},
{ {
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator : Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator", "TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator : Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator",
"Kind": "Removal" "Kind": "Removal"
}, },
{ {
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentActivator : Microsoft.AspNetCore.Mvc.ViewComponents.IViewComponentActivator", "TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Internal.ITypeActivatorCache typeActivatorCache)", "MemberId": "protected .ctor(Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine viewEngine, System.Diagnostics.DiagnosticSource diagnosticSource)",
"Kind": "Removal" "Kind": "Removal"
}, },
{ {
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultValidationHtmlAttributeProvider : Microsoft.AspNetCore.Mvc.ViewFeatures.ValidationHtmlAttributeProvider", "TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor",
"MemberId": "public .ctor(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcViewOptions> optionsAccessor, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.Internal.ClientValidatorCache clientValidatorCache)", "MemberId": "protected System.Diagnostics.DiagnosticSource get_DiagnosticSource()",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor",
"MemberId": "public .ctor(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcViewOptions> viewOptions, Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine viewEngine, Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory tempDataFactory, System.Diagnostics.DiagnosticSource diagnosticSource, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider modelMetadataProvider)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentActivator : Microsoft.AspNetCore.Mvc.ViewComponents.IViewComponentActivator",
"MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Internal.ITypeActivatorCache typeActivatorCache)",
"Kind": "Removal" "Kind": "Removal"
}, },
{ {
@ -44,7 +58,18 @@
"Kind": "Removal" "Kind": "Removal"
}, },
{ {
"TypeId": "public class Microsoft.AspNetCore.Mvc.RemoteAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IClientModelValidator", "TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultValidationHtmlAttributeProvider : Microsoft.AspNetCore.Mvc.ViewFeatures.ValidationHtmlAttributeProvider",
"Kind": "Removal" "MemberId": "public .ctor(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcViewOptions> optionsAccessor, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.Internal.ClientValidatorCache clientValidatorCache)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.PartialViewResultExecutor : Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor, Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor<Microsoft.AspNetCore.Mvc.PartialViewResult>",
"MemberId": "public .ctor(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcViewOptions> viewOptions, Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine viewEngine, Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory tempDataFactory, System.Diagnostics.DiagnosticSource diagnosticSource, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider modelMetadataProvider)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor : Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor, Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor<Microsoft.AspNetCore.Mvc.ViewResult>",
"MemberId": "public .ctor(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcViewOptions> viewOptions, Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine viewEngine, Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory tempDataFactory, System.Diagnostics.DiagnosticSource diagnosticSource, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider modelMetadataProvider)",
"Kind": "Removal"
} }
] ]

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
{ {
// Arrange // Arrange
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore")); services.AddSingleton<DiagnosticListener>(new DiagnosticListener("Microsoft.AspNetCore"));
services.AddLogging(); services.AddLogging();
services.AddMvcCore(o => o.EnableEndpointRouting = false); services.AddMvcCore(o => o.EnableEndpointRouting = false);
var serviceProvider = services.BuildServiceProvider(); var serviceProvider = services.BuildServiceProvider();
@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
{ {
// Arrange // Arrange
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore")); services.AddSingleton<DiagnosticListener>(new DiagnosticListener("Microsoft.AspNetCore"));
services.AddLogging(); services.AddLogging();
services.AddMvcCore(o => o.EnableEndpointRouting = true); services.AddMvcCore(o => o.EnableEndpointRouting = true);
var serviceProvider = services.BuildServiceProvider(); var serviceProvider = services.BuildServiceProvider();

View File

@ -276,14 +276,14 @@ namespace Microsoft.AspNetCore.Mvc.Filters
var actionContext = new ActionContext(httpContext, new RouteData(), actionDescriptor); var actionContext = new ActionContext(httpContext, new RouteData(), actionDescriptor);
var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore"); var diagnosticListener = new DiagnosticListener("Microsoft.AspNetCore");
diagnosticSource.SubscribeWithAdapter(new TestDiagnosticListener()); diagnosticListener.SubscribeWithAdapter(new TestDiagnosticListener());
var invoker = new TestControllerActionInvoker( var invoker = new TestControllerActionInvoker(
filters, filters,
new MockControllerFactory(controller ?? this), new MockControllerFactory(controller ?? this),
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(), new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
diagnosticSource, diagnosticListener,
new ActionResultTypeMapper(), new ActionResultTypeMapper(),
actionContext, actionContext,
new List<IValueProviderFactory>(), new List<IValueProviderFactory>(),
@ -388,14 +388,14 @@ namespace Microsoft.AspNetCore.Mvc.Filters
IFilterMetadata[] filters, IFilterMetadata[] filters,
MockControllerFactory controllerFactory, MockControllerFactory controllerFactory,
ILogger logger, ILogger logger,
DiagnosticSource diagnosticSource, DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper, IActionResultTypeMapper mapper,
ActionContext actionContext, ActionContext actionContext,
IReadOnlyList<IValueProviderFactory> valueProviderFactories, IReadOnlyList<IValueProviderFactory> valueProviderFactories,
int maxAllowedErrorsInModelState) int maxAllowedErrorsInModelState)
: base( : base(
logger, logger,
diagnosticSource, diagnosticListener,
mapper, mapper,
CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState), CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState),
CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory), CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory),

View File

@ -111,8 +111,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
var activator = new Mock<IRazorPageActivator>(); var activator = new Mock<IRazorPageActivator>();
var adapter = new TestDiagnosticListener(); var adapter = new TestDiagnosticListener();
var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"); var diagnosticListener = new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor");
diagnosticSource.SubscribeWithAdapter(adapter); diagnosticListener.SubscribeWithAdapter(adapter);
var view = new RazorView( var view = new RazorView(
Mock.Of<IRazorViewEngine>(), Mock.Of<IRazorViewEngine>(),
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
new IRazorPage[0], new IRazorPage[0],
page, page,
new HtmlTestEncoder(), new HtmlTestEncoder(),
diagnosticSource); diagnosticListener);
var viewContext = CreateViewContext(view); var viewContext = CreateViewContext(view);
var expectedWriter = viewContext.Writer; var expectedWriter = viewContext.Writer;

View File

@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
IModelMetadataProvider provider = null, IModelMetadataProvider provider = null,
IUrlHelperFactory urlHelperFactory = null, IUrlHelperFactory urlHelperFactory = null,
IJsonHelper jsonHelper = null, IJsonHelper jsonHelper = null,
DiagnosticSource diagnosticSource = null, DiagnosticListener diagnosticListener = null,
HtmlEncoder htmlEncoder = null, HtmlEncoder htmlEncoder = null,
IModelExpressionProvider modelExpressionProvider = null) IModelExpressionProvider modelExpressionProvider = null)
{ {
@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
provider ?? Mock.Of<IModelMetadataProvider>(), provider ?? Mock.Of<IModelMetadataProvider>(),
urlHelperFactory ?? Mock.Of<IUrlHelperFactory>(), urlHelperFactory ?? Mock.Of<IUrlHelperFactory>(),
jsonHelper ?? Mock.Of<IJsonHelper>(), jsonHelper ?? Mock.Of<IJsonHelper>(),
diagnosticSource ?? new DiagnosticListener("Microsoft.AspNetCore.Mvc.RazorPages"), diagnosticListener ?? new DiagnosticListener("Microsoft.AspNetCore.Mvc.RazorPages"),
htmlEncoder ?? HtmlEncoder.Default, htmlEncoder ?? HtmlEncoder.Default,
modelExpressionProvider ?? Mock.Of<IModelExpressionProvider>()); modelExpressionProvider ?? Mock.Of<IModelExpressionProvider>());
} }

View File

@ -264,7 +264,9 @@ namespace Microsoft.AspNetCore.Mvc
{ {
var serviceCollection = new ServiceCollection(); var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(new ApplicationPartManager()); serviceCollection.AddSingleton(new ApplicationPartManager());
serviceCollection.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore.Mvc")); var diagnosticListener = new DiagnosticListener("Microsoft.AspNetCore.Mvc");
serviceCollection.AddSingleton<DiagnosticSource>(diagnosticListener);
serviceCollection.AddSingleton<DiagnosticListener>(diagnosticListener);
serviceCollection.AddMvc(); serviceCollection.AddMvc();
serviceCollection serviceCollection
.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>() .AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()

View File

@ -261,7 +261,10 @@ namespace Microsoft.AspNetCore.Mvc
services.AddSingleton<IHostingEnvironment>(GetHostingEnvironment()); services.AddSingleton<IHostingEnvironment>(GetHostingEnvironment());
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>(); services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNet"));
var diagnosticListener = new DiagnosticListener("Microsoft.AspNet");
services.AddSingleton<DiagnosticSource>(diagnosticListener);
services.AddSingleton<DiagnosticListener>(diagnosticListener);
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()); services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
services.AddLogging(); services.AddLogging();
services.AddOptions(); services.AddOptions();

View File

@ -210,12 +210,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public void FindView_WritesDiagnostic_ViewFound() public void FindView_WritesDiagnostic_ViewFound()
{ {
// Arrange // Arrange
var diagnosticSource = new DiagnosticListener("Test"); var diagnosticListener = new DiagnosticListener("Test");
var listener = new TestDiagnosticListener(); var listener = new TestDiagnosticListener();
diagnosticSource.SubscribeWithAdapter(listener); diagnosticListener.SubscribeWithAdapter(listener);
var context = GetActionContext(); var context = GetActionContext();
var executor = GetViewExecutor(diagnosticSource); var executor = GetViewExecutor(diagnosticListener);
var viewName = "myview"; var viewName = "myview";
var viewResult = new PartialViewResult var viewResult = new PartialViewResult
@ -243,12 +243,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public void FindView_WritesDiagnostic_ViewNotFound() public void FindView_WritesDiagnostic_ViewNotFound()
{ {
// Arrange // Arrange
var diagnosticSource = new DiagnosticListener("Test"); var diagnosticListener = new DiagnosticListener("Test");
var listener = new TestDiagnosticListener(); var listener = new TestDiagnosticListener();
diagnosticSource.SubscribeWithAdapter(listener); diagnosticListener.SubscribeWithAdapter(listener);
var context = GetActionContext(); var context = GetActionContext();
var executor = GetViewExecutor(diagnosticSource); var executor = GetViewExecutor(diagnosticListener);
var viewName = "myview"; var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict); var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
@ -342,11 +342,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName }); return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName });
} }
private PartialViewResultExecutor GetViewExecutor(DiagnosticSource diagnosticSource = null) private PartialViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticListener = null)
{ {
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
diagnosticSource = new DiagnosticListener("Test"); diagnosticListener = new DiagnosticListener("Test");
} }
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict); var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
@ -367,7 +367,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
new TestHttpResponseStreamWriterFactory(), new TestHttpResponseStreamWriterFactory(),
new CompositeViewEngine(options), new CompositeViewEngine(options),
new TempDataDictionaryFactory(new SessionStateTempDataProvider()), new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
diagnosticSource, diagnosticListener,
NullLoggerFactory.Instance, NullLoggerFactory.Instance,
new EmptyModelMetadataProvider()); new EmptyModelMetadataProvider());

View File

@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Mvc
} }
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource>(diagnosticSource); services.AddSingleton<DiagnosticListener>(diagnosticSource);
services.AddSingleton<ViewComponentInvokerCache>(); services.AddSingleton<ViewComponentInvokerCache>();
services.AddSingleton<ExpressionTextCache>(); services.AddSingleton<ExpressionTextCache>();
services.AddSingleton(Options.Create(new MvcViewOptions())); services.AddSingleton(Options.Create(new MvcViewOptions()));

View File

@ -355,7 +355,7 @@ namespace Microsoft.AspNetCore.Mvc
var serviceProvider = new Mock<IServiceProvider>(); var serviceProvider = new Mock<IServiceProvider>();
serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))) serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine)))
.Returns(viewEngine.Object); .Returns(viewEngine.Object);
serviceProvider.Setup(p => p.GetService(typeof(DiagnosticSource))) serviceProvider.Setup(p => p.GetService(typeof(DiagnosticListener)))
.Returns(new DiagnosticListener("Test")); .Returns(new DiagnosticListener("Test"));
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
@ -519,7 +519,7 @@ namespace Microsoft.AspNetCore.Mvc
diagnosticSource.SubscribeWithAdapter(diagnosticListener); diagnosticSource.SubscribeWithAdapter(diagnosticListener);
var serviceProvider = new Mock<IServiceProvider>(); var serviceProvider = new Mock<IServiceProvider>();
serviceProvider.Setup(s => s.GetService(typeof(DiagnosticSource))).Returns(diagnosticSource); serviceProvider.Setup(s => s.GetService(typeof(DiagnosticListener))).Returns(diagnosticSource);
var httpContext = new DefaultHttpContext(); var httpContext = new DefaultHttpContext();
httpContext.RequestServices = serviceProvider.Object; httpContext.RequestServices = serviceProvider.Object;

View File

@ -235,10 +235,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
var adapter = new TestDiagnosticListener(); var adapter = new TestDiagnosticListener();
var diagnosticSource = new DiagnosticListener("Test"); var diagnosticListener = new DiagnosticListener("Test");
diagnosticSource.SubscribeWithAdapter(adapter); diagnosticListener.SubscribeWithAdapter(adapter);
var viewExecutor = CreateViewExecutor(diagnosticSource); var viewExecutor = CreateViewExecutor(diagnosticListener);
// Act // Act
await viewExecutor.ExecuteAsync( await viewExecutor.ExecuteAsync(
@ -351,11 +351,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
return view.Object; return view.Object;
} }
private ViewExecutor CreateViewExecutor(DiagnosticListener diagnosticSource = null) private ViewExecutor CreateViewExecutor(DiagnosticListener diagnosticListener = null)
{ {
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
diagnosticSource = new DiagnosticListener("Test"); diagnosticListener = new DiagnosticListener("Test");
} }
return new ViewExecutor( return new ViewExecutor(
@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
new TestHttpResponseStreamWriterFactory(), new TestHttpResponseStreamWriterFactory(),
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object, new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
new TempDataDictionaryFactory(new SessionStateTempDataProvider()), new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
diagnosticSource, diagnosticListener,
new EmptyModelMetadataProvider()); new EmptyModelMetadataProvider());
} }
} }

View File

@ -206,12 +206,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public void FindView_WritesDiagnostic_ViewFound() public void FindView_WritesDiagnostic_ViewFound()
{ {
// Arrange // Arrange
var diagnosticSource = new DiagnosticListener("Test"); var diagnosticListener = new DiagnosticListener("Test");
var listener = new TestDiagnosticListener(); var listener = new TestDiagnosticListener();
diagnosticSource.SubscribeWithAdapter(listener); diagnosticListener.SubscribeWithAdapter(listener);
var context = GetActionContext(); var context = GetActionContext();
var executor = GetViewExecutor(diagnosticSource); var executor = GetViewExecutor(diagnosticListener);
var viewName = "myview"; var viewName = "myview";
var viewResult = new ViewResult var viewResult = new ViewResult
@ -239,12 +239,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public void FindView_WritesDiagnostic_ViewNotFound() public void FindView_WritesDiagnostic_ViewNotFound()
{ {
// Arrange // Arrange
var diagnosticSource = new DiagnosticListener("Test"); var diagnosticListener = new DiagnosticListener("Test");
var listener = new TestDiagnosticListener(); var listener = new TestDiagnosticListener();
diagnosticSource.SubscribeWithAdapter(listener); diagnosticListener.SubscribeWithAdapter(listener);
var context = GetActionContext(); var context = GetActionContext();
var executor = GetViewExecutor(diagnosticSource); var executor = GetViewExecutor(diagnosticListener);
var viewName = "myview"; var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict); var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
@ -332,11 +332,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName }); return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName });
} }
private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null) private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticListener = null)
{ {
if (diagnosticSource == null) if (diagnosticListener == null)
{ {
diagnosticSource = new DiagnosticListener("Test"); diagnosticListener = new DiagnosticListener("Test");
} }
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict); var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
@ -357,7 +357,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
new TestHttpResponseStreamWriterFactory(), new TestHttpResponseStreamWriterFactory(),
new CompositeViewEngine(options), new CompositeViewEngine(options),
new TempDataDictionaryFactory(new SessionStateTempDataProvider()), new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
diagnosticSource, diagnosticListener,
NullLoggerFactory.Instance, NullLoggerFactory.Instance,
new EmptyModelMetadataProvider()); new EmptyModelMetadataProvider());