Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Configure ( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) {
- loggerFactory.AddConsole( Configuration.GetSection( "Logging" ) );
- loggerFactory.AddDebug();
- loggerFactory.AddFile(@"C:LogsPortalportal-{Date}.txt");
- public class BenchmarkFilter : IActionFilter
- {
- private readonly ILogger _logger;
- private readonly bool _isBenchmarkOn;
- private string _benchmarkFilePath;
- private Stopwatch _stopWatch = new Stopwatch();
- public BenchmarkFilter(ILoggerFactory loggerFactory, IOptions<AppSettings> appSettings)
- {
- _isBenchmarkOn = appSettings.Value.EnableBenchmarkLogging;
- _benchmarkFilePath = appSettings.Value.BenchmarkFilePath;
- }
- public void OnActionExecuting(ActionExecutingContext context)
- {
- if (_isBenchmarkOn)
- {
- _stopWatch = Stopwatch.StartNew();
- }
- }
- public void OnActionExecuted(ActionExecutedContext context)
- {
- if (_stopWatch.IsRunning)
- {
- _stopWatch.Stop();
- var seconds = _stopWatch.ElapsedMilliseconds;
- //logging to do
- }
- }
- }
Add Comment
Please, Sign In to add comment