The logger now supports colors

This commit is contained in:
2023-07-05 19:30:38 +03:00
parent ac7212ca00
commit a7a71bf49a
8 changed files with 63 additions and 21 deletions

View File

@@ -17,8 +17,9 @@ public class Exit : ICommandAction
{
if (args is null || args.Length == 0)
{
Config.Logger.Log("Exiting...", "Exit");
Config.Data.Save();
Config.Logger.Log("Exiting...", "Exit", isInternal:false);
await Config.Data.Save();
await Config.Logger.SaveToFile();
Environment.Exit(0);
}
else
@@ -32,7 +33,7 @@ public class Exit : ICommandAction
break;
case "force":
Config.Logger.Log("Exiting...", "Exit");
Config.Logger.Log("Exiting (FORCE)...", "Exit", LogLevel.WARNING, false);
Environment.Exit(0);
break;

View File

@@ -36,7 +36,7 @@ public static class Installer
Config.Data.Add("ServerID", serverId);
}
Config.Logger.Log("Config Saved", "Installer");
Config.Logger.Log("Config Saved", "Installer", isInternal:true);
Config.Data.Save();

View File

@@ -165,7 +165,24 @@ public class Program
URLs = new Json<string, string>("./Data/Resources/URLs.json");
Logger.LogEvent += (message, type) => { Console.WriteLine(message); };
Logger.LogEvent += (message, type, isInternal) =>
{
if (isInternal) return;
if (type == LogLevel.INFO)
Console.ForegroundColor = ConsoleColor.Green;
else if (type == LogLevel.WARNING)
Console.ForegroundColor = ConsoleColor.DarkYellow;
else if (type == LogLevel.ERROR)
Console.ForegroundColor = ConsoleColor.Red;
else if(type == LogLevel.CRITICAL)
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($"[{type.ToString()}] {message}");
Console.ResetColor();
};
Console.WriteLine("Loading resources ...");