Guest User

Untitled

a guest
Feb 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public void Configure ( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) {
  2. loggerFactory.AddConsole( Configuration.GetSection( "Logging" ) );
  3. loggerFactory.AddDebug();
  4. loggerFactory.AddFile(@"C:LogsPortalportal-{Date}.txt");
  5.  
  6. public class BenchmarkFilter : IActionFilter
  7. {
  8. private readonly ILogger _logger;
  9. private readonly bool _isBenchmarkOn;
  10. private string _benchmarkFilePath;
  11.  
  12. private Stopwatch _stopWatch = new Stopwatch();
  13.  
  14. public BenchmarkFilter(ILoggerFactory loggerFactory, IOptions<AppSettings> appSettings)
  15. {
  16.  
  17. _isBenchmarkOn = appSettings.Value.EnableBenchmarkLogging;
  18. _benchmarkFilePath = appSettings.Value.BenchmarkFilePath;
  19. }
  20.  
  21. public void OnActionExecuting(ActionExecutingContext context)
  22. {
  23. if (_isBenchmarkOn)
  24. {
  25. _stopWatch = Stopwatch.StartNew();
  26. }
  27. }
  28.  
  29. public void OnActionExecuted(ActionExecutedContext context)
  30. {
  31. if (_stopWatch.IsRunning)
  32. {
  33. _stopWatch.Stop();
  34. var seconds = _stopWatch.ElapsedMilliseconds;
  35. //logging to do
  36.  
  37.  
  38. }
  39. }
  40.  
  41.  
  42.  
  43. }
Add Comment
Please, Sign In to add comment