cs-codex-dist-tests/Logging/BaseLog.cs

55 lines
1.2 KiB
C#
Raw Normal View History

2023-04-25 09:31:15 +00:00
using System.Diagnostics;
using Utils;
namespace Logging
2023-04-14 12:53:39 +00:00
{
public abstract class BaseLog
{
private bool hasFailed;
private LogFile? logFile;
2023-04-25 09:31:15 +00:00
private readonly bool debug;
protected BaseLog(bool debug)
{
this.debug = debug;
}
2023-04-14 12:53:39 +00:00
protected abstract LogFile CreateLogFile();
protected LogFile LogFile
{
get
{
if (logFile == null) logFile = CreateLogFile();
return logFile;
}
}
public void Log(string message)
{
LogFile.Write(message);
}
2023-04-25 09:31:15 +00:00
public void Debug(string message = "", int skipFrames = 0)
{
if (debug)
{
var callerName = DebugStack.GetCallerName(skipFrames);
Log($"(debug)({callerName}) {message}");
}
}
2023-04-14 12:53:39 +00:00
public void Error(string message)
{
Log($"[ERROR] {message}");
}
public void MarkAsFailed()
{
if (hasFailed) return;
hasFailed = true;
LogFile.ConcatToFilename("_FAILED");
}
}
}