You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
928B

  1. using Microsoft.Extensions.Logging;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HealthMonitor.Common
  9. {
  10. public class CustomizeStopWatch : IDisposable
  11. {
  12. private readonly Stopwatch _sw;
  13. private readonly string _domain;
  14. private readonly ILogger _logger;
  15. public string Content { get; set; } = default!;
  16. public CustomizeStopWatch(string domain, ILogger logger)
  17. {
  18. _domain = domain;
  19. _logger = logger;
  20. _sw = new Stopwatch();
  21. _sw.Start();
  22. }
  23. public void Dispose()
  24. {
  25. if (_sw != null)
  26. {
  27. _logger.LogInformation($"统计时间[{_domain}],耗时 {_sw.Elapsed.TotalMilliseconds} 毫秒 {Content}");
  28. _sw.Stop();
  29. }
  30. }
  31. }
  32. }