using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Firebird2D.Logger { public enum LogType { Info, Warning, Error } public static class GameLogger { private static readonly string LogFilePath = "Logs/Log.txt"; public static bool logActive { get { return _logActive; } set { _logActive = value; if (value == false) Log("Logger", LogType.Info, "Log Deactivated"); } } private static bool _logActive = true; public static void Initalize() { if (!Directory.Exists("Logs")) { Directory.CreateDirectory("Logs"); using (FileStream fileStream = File.Open(LogFilePath, FileMode.OpenOrCreate | FileMode.Append)) { AddText(fileStream, "===================" + System.DateTime.Today.ToString("dd,MM,yy") + "==================="); } } } public static void Log(string loggingInstance, LogType type, string message) { if (_logActive) { using (FileStream fileStream = File.Open(LogFilePath, FileMode.OpenOrCreate | FileMode.Append)) { AddText(fileStream, type.ToString("g") + ": " + loggingInstance + " -> " + message); fileStream.Close(); } } } private static void AddText(FileStream fs, string value) { byte[] info = new UTF8Encoding(true).GetBytes(value); fs.Write(info, 0, info.Length); } } }