diff --git a/EasyLogPlus/Config.cs b/EasyLogPlus/Config.cs index 56f33f7..70d3c1d 100644 --- a/EasyLogPlus/Config.cs +++ b/EasyLogPlus/Config.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EasyLogPlus { public class Config { @@ -13,12 +8,20 @@ public class Config { public string LogPath = Environment.CurrentDirectory + $@"\Application.log"; - public ConsoleColor DebugForeground = ConsoleColor.Blue; - public ConsoleColor InfoForeground = ConsoleColor.Gray; - public ConsoleColor NoticeForeground = ConsoleColor.Green; - public ConsoleColor WarningForeground = ConsoleColor.DarkYellow; - public ConsoleColor ErrorForeground = ConsoleColor.Red; + public ConsoleColor DebugText = ConsoleColor.Blue; + public ConsoleColor InfoText = System.Console.ForegroundColor; + public ConsoleColor NoticeText = ConsoleColor.Green; + public ConsoleColor WarningText = ConsoleColor.DarkYellow; + public ConsoleColor ErrorText = ConsoleColor.Red; + public ConsoleColor CriticalText = ConsoleColor.White; + public ConsoleColor AlertText = ConsoleColor.White; + public ConsoleColor EmergencyText = ConsoleColor.White; + public ConsoleColor DebugBackground = System.Console.BackgroundColor; + public ConsoleColor InfoBackground = System.Console.BackgroundColor; + public ConsoleColor NoticeBackground = System.Console.BackgroundColor; + public ConsoleColor WarningBackground = System.Console.BackgroundColor; + public ConsoleColor ErrorBackground = System.Console.BackgroundColor; public ConsoleColor CriticalBackground = ConsoleColor.DarkRed; public ConsoleColor AlertBackground = ConsoleColor.DarkBlue; public ConsoleColor EmergencyBackground = ConsoleColor.DarkMagenta; diff --git a/EasyLogPlus/Logger.cs b/EasyLogPlus/Logger.cs index 9e8f632..43da1e2 100644 --- a/EasyLogPlus/Logger.cs +++ b/EasyLogPlus/Logger.cs @@ -26,9 +26,7 @@ enum LogLevel { // trying to conform to the Syslog standard, found here } public string ProcessLogText(int level) { - if (isInit == false) { - return "Please Init logger first! you can init it by calling *YourLogName*.InitLogger();"; - } + if (isInit == false) { return "Please Init logger first! you can init it by calling *YourLogName*.InitLogger();"; } object text = string.Empty; @@ -82,8 +80,10 @@ public string ProcessLogText(int level) { public void Debug(object Content) { string LogText = ProcessLogText((int)LogLevel.Debug) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = cfg.DebugForeground); - Console.ForegroundColor = ConsoleColor.White; + Console.Write(LogText, Console.ForegroundColor = cfg.DebugText, + Console.BackgroundColor = cfg.DebugBackground); + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); @@ -92,18 +92,22 @@ public void Debug(object Content) { public void Info(object Content) { string LogText = ProcessLogText((int)LogLevel.Info) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = cfg.InfoForeground); - Console.ForegroundColor = ConsoleColor.White; + Console.Write(LogText, Console.ForegroundColor = cfg.InfoText, + Console.BackgroundColor = cfg.InfoBackground); + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); } - + public void Notice(object Content) { string LogText = ProcessLogText((int)LogLevel.Notice) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = cfg.NoticeForeground); - Console.ForegroundColor = ConsoleColor.White; + Console.Write(LogText, Console.ForegroundColor = cfg.NoticeText, + Console.BackgroundColor = cfg.NoticeBackground); + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); @@ -112,8 +116,10 @@ public void Notice(object Content) { public void Warning(object Content) { string LogText = ProcessLogText((int)LogLevel.Warning) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = cfg.WarningForeground); - Console.ForegroundColor = ConsoleColor.White; + Console.Write(LogText, Console.ForegroundColor = cfg.WarningText, + Console.BackgroundColor = cfg.WarningBackground); + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); @@ -122,9 +128,10 @@ public void Warning(object Content) { public void Error(object Content) { string LogText = ProcessLogText((int)LogLevel.Error) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = cfg.ErrorForeground); - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Black; + Console.Write(LogText, Console.ForegroundColor = cfg.ErrorText, + Console.BackgroundColor = cfg.ErrorBackground); + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); @@ -133,34 +140,34 @@ public void Error(object Content) { public void Critical(object Content) { string LogText = ProcessLogText((int)LogLevel.Critical) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White, + Console.Write(LogText, Console.ForegroundColor = cfg.CriticalText, Console.BackgroundColor = cfg.CriticalBackground); - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Black; + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); } - + public void Alert(object Content) { string LogText = ProcessLogText((int)LogLevel.Alert) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White, + Console.Write(LogText, Console.ForegroundColor = cfg.AlertText, Console.BackgroundColor = cfg.AlertBackground); - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Black; + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); } - + public void Emergency(object Content) { string LogText = ProcessLogText((int)LogLevel.Emergency) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White, + Console.Write(LogText, Console.ForegroundColor = cfg.EmergencyText, Console.BackgroundColor = cfg.EmergencyBackground); - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Black; + Console.ResetColor(); + Console.WriteLine(); } File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine); diff --git a/README.md b/README.md index 17fc215..c9a7ebb 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,23 @@ void SetConfig() // ENTIRELY optional, just add and change if you want. cfg.UseColon = true; // If set to true, uses `:` in logs instead of `=>` - cfg.DebugForeground = ConsoleColor.Blue; - cfg.InfoForeground = ConsoleColor.Gray; - cfg.NoticeForeground = ConsoleColor.Green; - cfg.WarningForeground = ConsoleColor.DarkYellow; - cfg.ErrorForeground = ConsoleColor.Red; - + cfg.LogPath = Environment.CurrentDirectory + $@"\Application.log"; // Sets where your Log saves and under what name + + // Logger color customization + cfg.DebugText = ConsoleColor.Blue; + cfg.InfoText = System.Console.ForegroundColor; + cfg.NoticeText = ConsoleColor.Green; + cfg.WarningText = ConsoleColor.DarkYellow; + cfg.ErrorText = ConsoleColor.Red; + cfg.CriticalText = ConsoleColor.White; + cfg.AlertText = ConsoleColor.White; + cfg.EmergencyText = ConsoleColor.White; + + cfg.DebugBackground = System.Console.BackgroundColor; + cfg.InfoBackground = System.Console.BackgroundColor; + cfg.NoticeBackground = System.Console.BackgroundColor; + cfg.WarningBackground = System.Console.BackgroundColor; + cfg.ErrorBackground = System.Console.BackgroundColor; cfg.CriticalBackground = ConsoleColor.DarkRed; cfg.AlertBackground = ConsoleColor.DarkBlue; cfg.EmergencyBackground = ConsoleColor.DarkMagenta; @@ -121,6 +132,7 @@ class Program { cfg.UseColon = false; cfg.CriticalBackground = ConsoleColor.Cyan; + cfg.NoticeText = ConsoleColor.Magenta; } static void Main(string[] args) {