diff --git a/.idea/.idea.EasyLogPlus/.idea/.gitignore b/.idea/.idea.EasyLogPlus/.idea/.gitignore new file mode 100644 index 0000000..15546bc --- /dev/null +++ b/.idea/.idea.EasyLogPlus/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/contentModel.xml +/modules.xml +/.idea.EasyLogPlus.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.EasyLogPlus/.idea/discord.xml b/.idea/.idea.EasyLogPlus/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/.idea.EasyLogPlus/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.EasyLogPlus/.idea/indexLayout.xml b/.idea/.idea.EasyLogPlus/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.EasyLogPlus/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.EasyLogPlus/.idea/vcs.xml b/.idea/.idea.EasyLogPlus/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.EasyLogPlus/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/EasyLog/Config.cs b/EasyLog/Config.cs deleted file mode 100644 index 412aa7d..0000000 --- a/EasyLog/Config.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EasyLog { - public class Config { - public bool ShowDate = true; - public bool Console = true; - public string LogPath = Environment.CurrentDirectory + @"\Application.log"; - public bool UseColon = true; - } -} \ No newline at end of file diff --git a/EasyLog.sln b/EasyLogPlus.sln similarity index 91% rename from EasyLog.sln rename to EasyLogPlus.sln index bcabb90..d42eaf9 100644 --- a/EasyLog.sln +++ b/EasyLogPlus.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.32106.194 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example.csproj", "{DE22B76E-763A-4019-A1D8-07EEF4592308}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyLog", "EasyLog\EasyLog.csproj", "{869CD7D8-113A-4D0B-B658-842DF1D5241F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyLogPlus", "EasyLogPlus\EasyLogPlus.csproj", "{869CD7D8-113A-4D0B-B658-842DF1D5241F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/EasyLogPlus/Config.cs b/EasyLogPlus/Config.cs new file mode 100644 index 0000000..56f33f7 --- /dev/null +++ b/EasyLogPlus/Config.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EasyLogPlus { + public class Config { + public bool ShowDate = true; + public bool Console = true; + public bool UseColon = true; + + 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 CriticalBackground = ConsoleColor.DarkRed; + public ConsoleColor AlertBackground = ConsoleColor.DarkBlue; + public ConsoleColor EmergencyBackground = ConsoleColor.DarkMagenta; + } +} \ No newline at end of file diff --git a/EasyLog/EasyLog.csproj b/EasyLogPlus/EasyLogPlus.csproj similarity index 68% rename from EasyLog/EasyLog.csproj rename to EasyLogPlus/EasyLogPlus.csproj index a1718e2..a4c95be 100644 --- a/EasyLog/EasyLog.csproj +++ b/EasyLogPlus/EasyLogPlus.csproj @@ -5,11 +5,11 @@ Library net6.0 false - EasyLog - 1.0.6-pre1 - 0x74 - Simple and easy to use logging system. - https://github.com/asoji/EasyLog + EasyLogPlus + 1.0.6-pre2 + 0x74, extended by asoji + Simple and easy to use logging system. Extended by asoji. + https://github.com/asoji/EasyLogPlus diff --git a/EasyLog/Logger.cs b/EasyLogPlus/Logger.cs similarity index 59% rename from EasyLog/Logger.cs rename to EasyLogPlus/Logger.cs index 9598303..9e8f632 100644 --- a/EasyLog/Logger.cs +++ b/EasyLogPlus/Logger.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace EasyLog { +namespace EasyLogPlus { public class Logger { public Config cfg; public bool isInit = false; @@ -13,12 +13,16 @@ public void InitLogger() { isInit = true; } - enum LogLevel { - Info = 0, - Debug, - Warning, - Error, - Critical + enum LogLevel { // trying to conform to the Syslog standard, found here + // https://en.wikipedia.org/wiki/Syslog#Severity_level + Debug = 7, + Info = 6, + Notice = 5, + Warning = 4, + Error = 3, + Critical = 2, + Alert = 1, + Emergency = 0 } public string ProcessLogText(int level) { @@ -29,13 +33,17 @@ public string ProcessLogText(int level) { object text = string.Empty; switch (level) { + case (int)LogLevel.Debug: + if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; + text += "DEBUG"; + break; case (int)LogLevel.Info: if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; text += "INFO"; break; - case (int)LogLevel.Debug: + case (int)LogLevel.Notice: if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; - text += "DEBUG"; + text += "NOTICE"; break; case (int)LogLevel.Warning: if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; @@ -49,6 +57,14 @@ public string ProcessLogText(int level) { if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; text += "CRITICAL"; break; + case (int)LogLevel.Alert: + if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; + text += "ALERT"; + break; + case (int)LogLevel.Emergency: + if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | "; + text += "EMERGENCY"; + break; } switch (cfg.UseColon) { @@ -66,7 +82,7 @@ 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 = ConsoleColor.Blue); + Console.WriteLine(LogText, Console.ForegroundColor = cfg.DebugForeground); Console.ForegroundColor = ConsoleColor.White; } @@ -76,7 +92,17 @@ 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 = ConsoleColor.White); + Console.WriteLine(LogText, Console.ForegroundColor = cfg.InfoForeground); + Console.ForegroundColor = ConsoleColor.White; + } + + 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; } @@ -86,7 +112,7 @@ public void Info(object Content) { public void Warning(object Content) { string LogText = ProcessLogText((int)LogLevel.Warning) + Content; if (cfg.Console) { - Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.DarkYellow); + Console.WriteLine(LogText, Console.ForegroundColor = cfg.WarningForeground); Console.ForegroundColor = ConsoleColor.White; } @@ -96,7 +122,7 @@ 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 = ConsoleColor.Red); + Console.WriteLine(LogText, Console.ForegroundColor = cfg.ErrorForeground); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; } @@ -108,7 +134,31 @@ public void Critical(object Content) { string LogText = ProcessLogText((int)LogLevel.Critical) + Content; if (cfg.Console) { Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White, - Console.BackgroundColor = ConsoleColor.DarkRed); + Console.BackgroundColor = cfg.CriticalBackground); + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Black; + } + + 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.BackgroundColor = cfg.AlertBackground); + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Black; + } + + 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.BackgroundColor = cfg.EmergencyBackground); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; } diff --git a/EasyLog/Properties/AssemblyInfo.cs b/EasyLogPlus/Properties/AssemblyInfo.cs similarity index 79% rename from EasyLog/Properties/AssemblyInfo.cs rename to EasyLogPlus/Properties/AssemblyInfo.cs index fb074d8..c3ad457 100644 --- a/EasyLog/Properties/AssemblyInfo.cs +++ b/EasyLogPlus/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("EasyLog")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] +[assembly: AssemblyTitle("EasyLogPlus")] +[assembly: AssemblyDescription("Simple and easy to use logging system. Extended by asoji.")] +[assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("EasyLog")] +[assembly: AssemblyProduct("EasyLogPlus")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.6.0")] +[assembly: AssemblyFileVersion("1.0.6.0")] diff --git a/Example/Example.csproj b/Example/Example.csproj index e60d2b9..5e67bf0 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -4,7 +4,7 @@ net6.0 - + diff --git a/Example/Program.cs b/Example/Program.cs index 4c416ad..e96a36d 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -1,6 +1,6 @@ using System; using System.IO; -using EasyLog; +using EasyLogPlus; namespace Example { class Program { @@ -9,21 +9,27 @@ class Program { //If you want change logger settings create function like this and call it when application starts static void SetConfig() { - cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; //Set path where you want log to be saved - cfg.ShowDate = true; //If this is set to true it will add date to the log - cfg.Console = true; //If this is set to true it will print the log to Console too + cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; // Set path where you want log to be saved + cfg.ShowDate = true; // If this is set to true it will add date to the log + cfg.Console = true; // If this is set to true it will print the log to Console too } static void Main(string[] args) { SetConfig(); log.cfg = cfg; - log.InitLogger(); //Call this to init logger - log.Info("This is info text!"); + log.InitLogger(); // Call this to init logger + log.Debug("This is debug text!"); + log.Info("This is info text!"); + log.Notice("This is notice text!"); log.Warning("This is warning text!"); log.Error("This is error text!"); log.Critical("This is critical text!"); + log.Alert("This is alert text!"); + log.Emergency("This is emergency text!"); + log.Info("Press any key to stop this example!"); + Console.ReadKey(); } } diff --git a/LICENSE b/LICENSE index 724f31b..3efc66a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) 2022 0x74 +Copyright (c) 2022 Asoji Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index dde3238..2ce2add 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,70 @@

- EasyLog + EasyLogPlus

- Simple and easy to use logging system. + Simple and easy to use logging system originally created by 0x74. Extended by asoji. +
+

+## What's different between this and the original repo? +- Uses .NET 6 instead of .NET Framework 4.x +- The text is more way readable [in my opinion]* +- Customizable severity level colors +- Added the whole Syslog Severity Level standardization [[read about that here](https://en.wikipedia.org/wiki/Syslog#Severity_level)], cranking from 4 severity levels to 8. +- Uses your local timezone in logs instead of UTC timezone +- Switchable between `:` and `=>` in logs, like `NOTICE: This is notice text!` or `NOTICE => This is notice text!` using `cfg.UseColon` +- **Probably a lot of breaking changes**, but I plan on basically keeping this seperate from the original project. + +Basically, I should've just made my own logger considering how much I changed, but eh, this fork works, and I'm pretty happy with it. + +*- This is what the original looked like on my screen in Rider and **oh no**. + +![ohno](https://user-images.githubusercontent.com/99072163/186800223-deffa9b9-eea4-40bc-a148-5d3262abf8de.png) + +It looks a lot better like this now + +![ohyes](https://user-images.githubusercontent.com/99072163/186800405-88117e0d-6ce8-4504-97cd-b477f15cfd78.png) + ## How to use? -- Install Easy-Log from nuget or run this command in NuGet Package manager ``` Install-Package Easy-Log -Version 1.0.5 ``` -- Add ``` using EasyLog; ``` +- Install EasyLog from GitHub's NuGet Registry, instructions [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#installing-a-package), make sure it's authors are `0x74, extended by asoji` +- Add `using EasyLog;` to top Then add ```cs Logger log = new Logger(); Config cfg = new Config(); ``` -If you want customize settings add + + +## Customization Options +If you want customize settings add these, keeping in mind that this whole `SetConfig()` is optional, and not required to run the application. ```cs void SetConfig() { - cfg.LogPath = Environment.CurrentDirectory + @"\Application.log";//Set path where you want log to be saved - cfg.ShowDate = true;//If this is set to true it will add date to the log - cfg.Console = true;//If this is set to true it will print the log to Console too + cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; //Set path where you want log to be saved + cfg.ShowDate = true; // If this is set to true it will add date to the log + cfg.Console = true; // If this is set to true it will print the log to Console too + + // 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.CriticalBackground = ConsoleColor.DarkRed; + cfg.AlertBackground = ConsoleColor.DarkBlue; + cfg.EmergencyBackground = ConsoleColor.DarkMagenta; } ``` -Then in your application main void add these +Then in your application main void add these, **this is required**. ```cs log.cfg = cfg; SetConfig(); -log.InitLogger();//Call this to init logger +log.InitLogger(); // Call this to init logger ``` ## Sending logs @@ -41,6 +78,11 @@ log.Debug("Hello from log, this is debug"); log.Info("Hello from log, this is info"); ``` +- Notice Log +```cs +log.Notice("Hello from log, this is notice"); +``` + - Warning Log ```cs log.Warning("Hello from log, this is warning"); @@ -50,3 +92,55 @@ log.Warning("Hello from log, this is warning"); ```cs log.Error("Hello from log, this is error"); ``` + +- Critical Log +```cs +log.Critical("Hello from log, this is critical") +``` + +- Alert Log +```cs +log.Alert("Hello from log, this is alert") +``` + +- Emergency Log +```cs +log.Emergency("Hello from log, this is emergency") +``` + +## [terrible] Example + +```cs +class Program { + static Logger log = new Logger(); + static Config cfg = new Config(); + + static void SetConfig() { + cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; + cfg.ShowDate = true; + cfg.Console = true; + + cfg.UseColon = false; + + cfg.CriticalBackground = ConsoleColor.Cyan; + } + + static void Main(string[] args) { + SetConfig(); + log.cfg = cfg; + log.InitLogger(); + + try { + // do some random shit + } catch (ArgumentOutOfRangeException outOfRangeException) { + log.Error("hey something is out of range?"); + } + + Console.ReadKey(); + } + } +``` + +## License + +This project [well, fork] is [MIT Licensed](LICENSE). Thank you byte-0x74/0x74 for making the original lib C: \ No newline at end of file