From 735c43d581731032902797874f013df6879d3ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Sat, 1 Apr 2023 15:25:13 +0200 Subject: [PATCH] Added the possibility to generate a log message depending on the ``LogLevel`` (#91) --- PeyrSharp.Env/Logger.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/PeyrSharp.Env/Logger.cs b/PeyrSharp.Env/Logger.cs index 16bd07f..5b5a781 100644 --- a/PeyrSharp.Env/Logger.cs +++ b/PeyrSharp.Env/Logger.cs @@ -21,6 +21,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +using PeyrSharp.Enums; using System; using System.IO; @@ -72,5 +73,24 @@ public static void Log(string message, string filePath, params object[] formatSt File.AppendAllText(filePath, string.Format(message, formatString)); // Log } + + /// + /// Logs a message with the specified severity level, file path, and timestamp. + /// + /// The message to log. + /// The path to the file where the message was logged. + /// The timestamp for the log message. + /// The severity level for the log message. + public static void Log(string message, string filePath, DateTime dateTime, LogLevel logLevel) => Log($"[{LogLevelToString(logLevel)}] {message}", filePath, dateTime); + + private static string LogLevelToString(LogLevel level) => level switch + { + LogLevel.Error => "Error", + LogLevel.Warning => "Warning", + LogLevel.Info => "Info", + LogLevel.Critical => "Critical", + LogLevel.Debug => "Debug", + _ => "Misc" + }; } }