Class ServerTimingFilter
- Namespace
- Cuemon.AspNetCore.Mvc.Filters.Diagnostics
- Assembly
- Cuemon.AspNetCore.Mvc.dll
A filter that performs time measure profiling of action methods.
public class ServerTimingFilter : ConfigurableActionFilter<ServerTimingOptions>, IConfigurable<ServerTimingOptions>, IActionFilter, IFilterMetadata
- Inheritance
-
ServerTimingFilter
- Implements
- Inherited Members
Examples
The following example shows the constructor dependencies used when creating directly.
using System;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.AspNetCore.Mvc.Filters.Diagnostics;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace MyApp.Examples;
public static class ServerTimingFilterExample
{
public static void Demonstrate()
{
var options = Options.Create(new ServerTimingOptions
{
UseTimeMeasureProfiler = true,
SuppressHeaderPredicate = _ => false
});
using var loggerFactory = LoggerFactory.Create(_ => { });
var filter = new ServerTimingFilter(
options,
new SampleHostEnvironment(),
loggerFactory.CreateLogger<ServerTimingFilter>());
Console.WriteLine(filter.Options.UseTimeMeasureProfiler);
Console.WriteLine(filter.GetType().Name);
}
private sealed class SampleHostEnvironment : IHostEnvironment
{
public string EnvironmentName { get; set; } = Environments.Development;
public string ApplicationName { get; set; } = nameof(ServerTimingFilterExample);
public string ContentRootPath { get; set; } = AppContext.BaseDirectory;
public IFileProvider ContentRootFileProvider { get; set; } = new NullFileProvider();
}
}
Constructors
ServerTimingFilter(IOptions<ServerTimingOptions>, IHostEnvironment, ILogger<ServerTimingFilter>)
Initializes a new instance of the ServerTimingFilter class.
public ServerTimingFilter(IOptions<ServerTimingOptions> setup, IHostEnvironment environment, ILogger<ServerTimingFilter> logger)
Parameters
setupIOptions<ServerTimingOptions>The TimeMeasureOptions which need to be configured.
environmentIHostEnvironmentThe dependency injected IHostEnvironment.
loggerILogger<ServerTimingFilter>The dependency injected ILogger<TCategoryName>.
Methods
OnActionExecuted(ActionExecutedContext)
Called after the action executes, before the action result.
public override void OnActionExecuted(ActionExecutedContext context)
Parameters
contextActionExecutedContext
OnActionExecuting(ActionExecutingContext)
Called before the action executes, after model binding is complete.
public override void OnActionExecuting(ActionExecutingContext context)
Parameters
contextActionExecutingContext
See Also
ConfigurableActionFilter<TOptions>