60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Sarand.Net.Standard.Base.Core
|
|
{
|
|
//=======================================================================
|
|
public class ElapsedTimeLogger
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public ElapsedTimeLogger (String logPrefix, String logSuffix = "")
|
|
{
|
|
LogPrefix = logPrefix;
|
|
LogSuffix = logSuffix;
|
|
StartedAt = DateTime.Now;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public String LogPrefix { get; }
|
|
public String LogSuffix { get; }
|
|
public DateTime StartedAt { get; private set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public void Restart ()
|
|
{
|
|
StartedAt = DateTime.Now;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Logging.
|
|
public void LogElapsedSecs (bool restart = false)
|
|
{
|
|
LogElapsedSecs("", restart);
|
|
}
|
|
public void LogElapsedSecs (String logSuffix, bool restart = false)
|
|
{
|
|
LogElapsedSecs("", logSuffix, restart);
|
|
}
|
|
public void LogElapsedSecs (String logPrefix, String logSuffix, bool restart = false)
|
|
{
|
|
logPrefix = StringUtil.OnEmpty(logPrefix, LogPrefix);
|
|
logSuffix = StringUtil.OnEmpty(logSuffix, LogSuffix);
|
|
TimeSpan elapsed = DateTime.Now - StartedAt;
|
|
SaLogger.Info(StringUtil.TrimAll(logPrefix + " Elapsed: " + elapsed.TotalSeconds.ToString("0.000") + " secs. " + logSuffix));
|
|
if (restart) Restart();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|