Net.Like.Xue.Tokyo/Assets/BITKit/Core/Utility/StopWatcher.cs

28 lines
760 B
C#
Raw Normal View History

2024-12-09 22:57:08 +08:00
using System;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace BITKit
{
public class StopWatcher:IDisposable
{
private readonly Stopwatch _stopwatch = new Stopwatch();
private readonly ILogger _logger;
private readonly string _message;
2025-02-24 23:03:39 +08:00
public StopWatcher(ILogger logger,string message=null)
2024-12-09 22:57:08 +08:00
{
_logger = logger;
_message = message;
2025-02-24 23:03:39 +08:00
2024-12-28 23:19:55 +08:00
_logger.LogInformation($"开始计时:{message}");
_stopwatch.Start();
2024-12-09 22:57:08 +08:00
}
2024-12-28 23:19:55 +08:00
2024-12-09 22:57:08 +08:00
public void Dispose()
{
_stopwatch.Stop();
2024-12-28 23:19:55 +08:00
_logger.LogInformation($"已完成:{_message},耗时{_stopwatch.ElapsedMilliseconds}ms");
2024-12-09 22:57:08 +08:00
}
}
}