コード例 #1
0
 public TimeElapsedLogger(string description, CancellationToken cancellationToken, ILogLevelLogger logger)
 {
     _currentThreadIndent++;
     _description       = description;
     _cancellationToken = cancellationToken;
     _logger            = logger;
     _stopwatch         = Stopwatch.StartNew();
     if (logger.Enabled)
     {
         logger.Log("{0}{1}.", GetOpenIndent(_currentThreadIndent), _description);
     }
 }
コード例 #2
0
 public void Dispose()
 {
     _stopwatch.Stop();
     if (_logger.Enabled)
     {
         _logger.Log(
             "{0}{1} {2} {3:n0} msec - GC Memory: {4:n0} bytes.",
             GetCloseIndent(_currentThreadIndent),
             _description,
             _cancellationToken.IsCancellationRequested ? "cancelled after" : "completed in",
             _stopwatch.ElapsedMilliseconds,
             GC.GetTotalMemory(false));
     }
     _currentThreadIndent--;
 }