From 56cca36d1ab2671cb85c3065e91da313994158eb Mon Sep 17 00:00:00 2001 From: y2keui Date: Wed, 1 Apr 2026 22:06:18 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A1=9C=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lol_coder/lol_coder/Log/LogWriter.cs | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 lol_coder/lol_coder/Log/LogWriter.cs diff --git a/lol_coder/lol_coder/Log/LogWriter.cs b/lol_coder/lol_coder/Log/LogWriter.cs new file mode 100644 index 0000000..6895aeb --- /dev/null +++ b/lol_coder/lol_coder/Log/LogWriter.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace lol_coder.Log +{ + public class LogWriter + { + public enum LogType { Error, Display, Normal } + + #region Variables + public string LogFileName { get; set; } + public bool isShowLogNormal { get; set; } = true; + public bool isShowLogDisplay { get; set; } = false; + public bool isShowLogError { get; set; } = true; + + public Color colorLogNormal { get; set; } = Color.FromArgb(0, 0, 0); + public Color colorLogDisplay { get; set; } = Color.FromArgb(160, 50, 50); + public Color colorLogError { get; set; } = Color.FromArgb(230, 0, 0); + + public bool isSaveLogNormal { get; set; } = true; + public bool isSaveLogDisplay { get; set; } = false; + public bool isSaveLogError { get; set; } = true; + + #endregion + + #region Singleton + + private static LogWriter uniqueInstance = null; + private static readonly Object mInstanceLocker = new Object(); + + public static LogWriter getInstance() + { + lock (mInstanceLocker) + { + if (uniqueInstance == null) + { + uniqueInstance = new LogWriter(); + } + } + return uniqueInstance; + } + + #endregion + + #region Method + public void LogWrite(string logMessage, LogType logType) + { + string m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string folderPath = m_exePath + @"\Logs"; + DirectoryInfo di = new DirectoryInfo(folderPath); + if (!di.Exists) di.Create(); + + string suffix = ""; + switch (logType) + { + case LogType.Normal: suffix = " normal.txt"; break; + case LogType.Display: suffix = " display.txt"; break; + case LogType.Error: suffix = " error.txt"; break; + } + + + + try + { + using (StreamWriter w = File.AppendText(folderPath + @"\" + LogFileName + suffix)) + { + w.WriteLine(DateTime.Now.ToString("yyMMdd HH:mm:ss.fff : ") + logMessage); + } + } + catch (Exception ex) { } + } + + #endregion + } +}