public static void AfterOnActionExecution( this DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) { Debug.Assert(diagnosticListener != null); Debug.Assert(actionExecutedContext != null); Debug.Assert(filter != null); // Inlinable fast-path check if diagnostic listener is enabled if (diagnosticListener.IsEnabled()) { AfterOnActionExecutionImpl(diagnosticListener, actionExecutedContext, filter); } }
public static void BeforeOnActionExecution( this DiagnosticSource diagnosticSource, ActionExecutingContext actionExecutingContext, IAsyncActionFilter filter) { if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.BeforeOnActionExecution", new { actionDescriptor = actionExecutingContext.ActionDescriptor, actionExecutingContext = actionExecutingContext, filter = filter }); } }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { IFeatureManager featureManager = context.HttpContext.RequestServices.GetRequiredService <IFeatureManagerSnapshot>(); if (await featureManager.IsEnabledAsync(FeatureName).ConfigureAwait(false)) { var serviceProvider = context.HttpContext.RequestServices.GetRequiredService <IServiceProvider>(); IAsyncActionFilter filter = ActivatorUtilities.CreateInstance <T>(serviceProvider); await filter.OnActionExecutionAsync(context, next).ConfigureAwait(false); } else { await next().ConfigureAwait(false); } }
public async Task OnActionExecutionAsyncMethodHappyPath2() { const string messageFormat = "My message format: {0}"; const LogLevel logLevel = LogLevel.Info; const string exceptionMessageFormat = "My exception message format: {0}."; const LogLevel exceptionLogLevel = LogLevel.Fatal; const string actionName = "MyAction"; const string actionArgumentName = "foo"; const int actionArgument = 123; var mockActionFilter = new Mock <LoggingActionFilter>(messageFormat, null, logLevel); mockActionFilter.Object.ExceptionMessageFormat = exceptionMessageFormat; mockActionFilter.Object.ExceptionLogLevel = exceptionLogLevel; IAsyncActionFilter loggingActionFilter = mockActionFilter.Object; var mockLogger = new MockLogger(); var httpContext = new DefaultHttpContext() { RequestServices = GetServiceProvider(mockLogger.Object) }; var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor() { DisplayName = actionName }); var context = new ActionExecutingContext(actionContext, Array.Empty <IFilterMetadata>(), new Dictionary <string, object>(), null); context.ActionArguments.Add(actionArgumentName, actionArgument); var actionExecutedContext = new ActionExecutedContext(actionContext, Array.Empty <IFilterMetadata>(), null); var exception = actionExecutedContext.Exception = new Exception(); ActionExecutionDelegate next = () => Task.FromResult(actionExecutedContext); await loggingActionFilter.OnActionExecutionAsync(context, next); mockLogger.VerifyFatal(string.Format(exceptionMessageFormat, actionName), exception, new { foo = 123, ResponseStatusCode = 500 }, Times.Once()); }
public static void AfterOnActionExecution( this DiagnosticSource diagnosticSource, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) { Debug.Assert(diagnosticSource != null); Debug.Assert(actionExecutedContext != null); Debug.Assert(filter != null); if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.AfterOnActionExecution", new { actionDescriptor = actionExecutedContext.ActionDescriptor, actionExecutedContext = actionExecutedContext, filter = filter }); } }
private static void AfterOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) { if (diagnosticListener.IsEnabled(Diagnostics.AfterActionFilterOnActionExecutionEventData.EventName)) { diagnosticListener.Write( Diagnostics.AfterActionFilterOnActionExecutionEventData.EventName, new AfterActionFilterOnActionExecutionEventData( actionExecutedContext.ActionDescriptor, actionExecutedContext, filter )); } }
public static void AfterOnActionExecution( this DiagnosticSource diagnosticSource, ActionDescriptor actionDescriptor, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) { if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.AfterOnActionExecution", new { actionDescriptor = actionDescriptor, actionExecutedContext = actionExecutedContext, filter = filter }); } }
public static void BeforeOnActionExecution( this DiagnosticSource diagnosticSource, ActionExecutingContext actionExecutingContext, IAsyncActionFilter filter) { Debug.Assert(diagnosticSource != null); Debug.Assert(actionExecutingContext != null); Debug.Assert(filter != null); if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.BeforeOnActionExecution", new { actionDescriptor = actionExecutingContext.ActionDescriptor, actionExecutingContext = actionExecutingContext, filter = filter }); } }
private static void AfterOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) { if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) { diagnosticListener.Write( "Microsoft.AspNetCore.Mvc.AfterOnActionExecution", new { actionDescriptor = actionExecutedContext.ActionDescriptor, actionExecutedContext = actionExecutedContext, filter = filter }); } }
private static void BeforeOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IAsyncActionFilter filter) { if (diagnosticListener.IsEnabled(Diagnostics.BeforeOnActionExecution.EventName)) { diagnosticListener.Write( Diagnostics.BeforeOnActionExecution.EventName, new BeforeOnActionExecution( actionExecutingContext.ActionDescriptor, actionExecutingContext, filter )); } }