/// <summary> /// Gets the created logger instance. If the current logger instance is null and an existing logger class is defined /// in the LoggerClass private constant, then a new logger object will be created. Logger class must implement /// ITransloaditLogger interface. If the set class does not implement the required interface, then the default logger will be used. /// </summary> /// <exception cref="Transloadit.Log.Exception.LoggerClassNotFoundException"> /// Thrown when the configured class is not exsiting. /// </exception> /// <returns>Single logger instance, which is an implementation of ITransloaditLogger interface</returns> public static ITransloaditLogger GetLogger() { if (logger == null) { lock (sync) { string type = LoggerFactory.LoggerClass; Type t = Type.GetType(type); if (t == null) { throw new Exceptions.LoggerClassNotFoundException(type); } try { logger = (ITransloaditLogger)Activator.CreateInstance(t); } catch (Exception e) { logger = new TransloaditLogger(); LoggerFactory.GetLogger().LogError(Type.GetType("LoggerFactory"), e, "Custom logger instance cannot be created: {0}", t.Name); } } } return logger; }
/// <summary> /// Initializates the logger factory. If an existing logger class is defined in the app config, /// then a new logger object will be created. Logger class must implement ITransloaditLogger interface. /// If log element does not exist, or the set class does not implement the required interface, /// then the default logger wll be used. /// </summary> /// <exception cref="Transloadit.Log.Exception.UndefinedLoggerClassException"> /// Thrown when Transloadit log element is defined in the app config, but class attribute is not set. /// </exception> /// <exception cref="Transloadit.Log.Exception.LoggerClassNotFoundException"> /// Thrown when the configured class is not exsiting. /// </exception> static LoggerFactory() { TransloaditConfigSection section = (TransloaditConfigSection)ConfigurationManager.GetSection("transloadit"); if (section.TransloaditLogConfig.ElementInformation.IsPresent) { if (section.TransloaditLogConfig.Type == null) { throw new Exceptions.UndefinedLoggerClassException(); } Type t = Type.GetType(section.TransloaditLogConfig.Type); if (t == null) { throw new Exceptions.LoggerClassNotFoundException(section.TransloaditLogConfig.Type); } try { logger = (ITransloaditLogger)Activator.CreateInstance(t); } catch (Exception e) { LoggerFactory.GetLogger().LogError(Type.GetType("LoggerFactory"), e, "Custom logger instance cannot be created: {0}", t.Name); logger = new TransloaditLogger(); } } else { logger = new TransloaditLogger(); } }
/// <summary> /// Gets the created logger instance. If the current logger instance is null and an existing logger class is defined /// in the LoggerClass private constant, then a new logger object will be created. Logger class must implement /// ITransloaditLogger interface. If the set class does not implement the required interface, then the default logger will be used. /// </summary> /// <exception cref="Transloadit.Log.Exception.LoggerClassNotFoundException"> /// Thrown when the configured class is not exsiting. /// </exception> /// <returns>Single logger instance, which is an implementation of ITransloaditLogger interface</returns> public static ITransloaditLogger GetLogger() { if (logger == null) { lock (sync) { string type = LoggerFactory.LoggerClass; Type t = Type.GetType(type); if (t == null) { throw new Exceptions.LoggerClassNotFoundException(type); } try { logger = (ITransloaditLogger)Activator.CreateInstance(t); } catch (Exception e) { logger = new TransloaditLogger(); LoggerFactory.GetLogger().LogError(Type.GetType("LoggerFactory"), e, "Custom logger instance cannot be created: {0}", t.Name); } } } return(logger); }