//Blizzless Project 2022 //Blizzless Project 2022 using System; //Blizzless Project 2022 using System.Collections.Generic; //Blizzless Project 2022 using System.Diagnostics; namespace DiIiS_NA.Core.Logging { public static class LogManager { /// /// Is logging enabled? /// public static bool Enabled { get; set; } /// /// Available & configured log targets. /// internal static readonly List Targets = new(); /// /// Available loggers. /// internal readonly static Dictionary Loggers = new(); /// /// Creates and returns a logger named with declaring type. /// /// A instance. public static Logger CreateLogger() { var frame = new StackFrame(1, false); // read stack frame. var name = frame.GetMethod().DeclaringType.Name; // get declaring type's name. if (name == null) // see if we got a name. throw new Exception("Error getting full name for declaring type."); return CreateLogger(name); // return the newly created logger. } /// /// Creates and returns a logger with given name. /// /// /// A instance. public static Logger CreateLogger(string name) { if (!Loggers.ContainsKey(name)) // see if we already have instance for the given name. Loggers.Add(name, new Logger(name)); // add it to dictionary of loggers. return Loggers[name]; // return the newly created logger. } /// /// Attachs a new log target. /// /// public static void AttachLogTarget(LogTarget target) { Targets.Add(target); } } }