Replace verbose StringBuilder-based timestamp construction with a single DateTime format string. The method now returns the clock stamp using the format "[{DateTime.Now:dd-MM-yy HH:mm}] ", simplifying the code and improving readability while preserving the original output layout.
for issue 121
111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace SecondBotEvents
|
|
{
|
|
public enum ConsoleLogLogLevel
|
|
{
|
|
Status,
|
|
Info,
|
|
Crit,
|
|
Warn,
|
|
Debug,
|
|
};
|
|
public static class LogFormater
|
|
{
|
|
public static string Warn(string message,bool send_to_console)
|
|
{
|
|
return Add(message, ConsoleLogLogLevel.Warn, send_to_console);
|
|
}
|
|
public static string Crit(string message, bool send_to_console)
|
|
{
|
|
return Add(message, ConsoleLogLogLevel.Crit, send_to_console);
|
|
}
|
|
public static string Info(string message, bool send_to_console)
|
|
{
|
|
return Add(message, ConsoleLogLogLevel.Info, send_to_console);
|
|
}
|
|
public static string Status(string message, bool send_to_console)
|
|
{
|
|
return Add(message, ConsoleLogLogLevel.Status, send_to_console);
|
|
}
|
|
public static string Debug(string message, bool send_to_console)
|
|
{
|
|
return Add(message, ConsoleLogLogLevel.Debug, send_to_console);
|
|
}
|
|
public static string Warn(string message)
|
|
{
|
|
return Warn(message, true);
|
|
}
|
|
public static string Crit(string message)
|
|
{
|
|
return Crit(message, true);
|
|
}
|
|
public static string Info(string message)
|
|
{
|
|
return Info(message, true);
|
|
}
|
|
public static string Status(string message)
|
|
{
|
|
return Status(message, true);
|
|
}
|
|
public static string Debug(string message)
|
|
{
|
|
return Debug(message, true);
|
|
}
|
|
|
|
public static string GetClockStamp()
|
|
{
|
|
// Format: [dd-MM-yyyy HH:mm]
|
|
return $"[{DateTime.Now:dd-MM-yy HH:mm}] ";
|
|
}
|
|
|
|
private static string Add(string message, ConsoleLogLogLevel Level, bool send_to_console = true)
|
|
{
|
|
|
|
StringBuilder n = new();
|
|
n.Append(GetClockStamp());
|
|
switch (Level)
|
|
{
|
|
#if DEBUG
|
|
case ConsoleLogLogLevel.Debug:
|
|
{
|
|
n.Append("Debug - ");
|
|
break;
|
|
}
|
|
case ConsoleLogLogLevel.Info:
|
|
{
|
|
n.Append("Info - ");
|
|
break;
|
|
}
|
|
#endif
|
|
case ConsoleLogLogLevel.Status:
|
|
{
|
|
n.Append("Status - ");
|
|
break;
|
|
}
|
|
case ConsoleLogLogLevel.Warn:
|
|
{
|
|
n.Append("Warn - ");
|
|
break;
|
|
}
|
|
case ConsoleLogLogLevel.Crit:
|
|
{
|
|
n.Append("Crit - ");
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
n.Append("Log - ");
|
|
break;
|
|
}
|
|
}
|
|
n.Append(message);
|
|
if(send_to_console == true)
|
|
{
|
|
Console.WriteLine(n.ToString());
|
|
}
|
|
return n.ToString();
|
|
}
|
|
}
|
|
}
|