From 7c81920e84b5808fd47ea053187cdb8cacfa0149 Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Sat, 16 May 2026 14:12:16 +0200 Subject: [PATCH] [init:] logging system --- Logger.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Logger.cs diff --git a/Logger.cs b/Logger.cs new file mode 100644 index 0000000..51582b2 --- /dev/null +++ b/Logger.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using Newtonsoft.Json; + +namespace Logof_Client; + +public static class Logger +{ + public static void Log(string text, LogType logType = LogType.Info) + { + try + { + string config_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "logofclient"); + if (!Directory.Exists(config_path)) + Directory.CreateDirectory(config_path); + + string log_path = Path.Combine(config_path, $"log-{DateTime.Now:dd-MM-yy}.log"); + if(!File.Exists(log_path)) + File.Create(log_path).Close(); + + string[] line = [$"[{DateTime.Now:dd.MM.yyyy - T}]: ({logType.ToString()}) {text})"]; + Console.WriteLine(line); + + File.AppendAllLines(log_path, line); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + + } + + public enum LogType + { + Error, + Warning, + Info + } +} \ No newline at end of file