/// <summary> /// The initial call to setting up and using the BasicLogger. /// NOTE: This should be set by the consuming application at the very start of the program. <br></br> /// For example: /// <example> /// <code> /// BasicLogger.Construct().UseFileLogger("yourFilename.txt").Build(); <br></br> /// or <br></br> /// BasicLogger.Construct<BasicLoggerFactory>().UseFileLogger("yourFilename.txt").Build(); /// </code> /// </example> /// </summary> public static BasicLoggerFactory Construct <T>() where T : BasicLoggerFactory, new() { Factory = new T(); return(Factory); }
/// <summary> /// Add and build a factory dynamically. /// This is a helpful function for some scenarios where you need to add another <see cref="BasicLoggerFactory"/> in the run time. <br></br> /// <br></br> /// <strong> NOTE: Please be sure that you have already initiated the Factories by constructing one. Or it'll throw a <see cref="NullReferenceException"/></strong> /// </summary> /// <param name="factoryName">The name of the factory</param> /// <param name="factory">A <see cref="BasicLoggerFactory"/></param> public static void AddFactory(string factoryName, BasicLoggerFactory factory) { if (Factories == null) { throw new NullReferenceException("The Factories dictionary haven't been constructed yet. Make sure you have call the construct function first."); } try { Factories[factoryName] = factory; factory.FactoryName = factoryName; IoC.Logger.Log($"Add factory {factory.FactoryName} to Factories dynamically."); } catch (Exception ex) { HandleExceptions(nameof(MultiBasicLoggers.AddFactory), ex); } }
/// <summary> /// An extension method of BasicLoggerFactory. Use this function to build the factory after constructing all the loggers that are going to be used. <br></br> /// It comes with a <see cref="DebugLogger"/> by default. Current possible loggers are: <br></br> /// <see cref="DebugLogger"/> : Log in the output when build the application in debug mode. /// <see cref="ConsoleLogger"/> : Log in the console. /// <see cref="FileLogger"/> : Log in a file. /// </summary> /// <param name="factory"></param> public static void Build(this BasicLoggerFactory factory) { // Build the factory factory.Build(); }
/// <summary> /// A defaul construction method that construct a <see cref="BasicLoggerFactory"/> /// NOTE: This should be set by the consuming application at the very start of the program. <br></br> /// </summary> /// <returns></returns> public static BasicLoggerFactory Construct() { Factory = new BasicLoggerFactory(); return(Factory); }