/// <summary> /// Get a logger based on its name. /// </summary> /// <param name="name">name of the logger</param> /// <param name="plant">the log plant responsible for creating the said logger.</param> /// <returns>logger if found, or newly created logger if not found</returns> public ILogger GetLogger(string name, ILogPlant plant) { if (name == null) { throw new ArgumentNullException("name"); } if (plant == null) { throw new ArgumentNullException("plant"); } LoggerHash hash = new LoggerHash(name); lock (this.v_rankTable) { Logger logger = this.v_rankTable[hash] as Logger; if (logger == null) { logger = plant.GrowLogger(name); logger.Rank = this; this.InformParents(logger); lock (this) { this.v_rankTable[hash] = logger; } //this.OnLoggerCreatedEvent(logger); return(logger); } return(logger); } }
public override bool Equals(object obj) { if (this == obj) { return(true); } LoggerHash key = obj as LoggerHash; return((key != null) && (this.v_name == key.v_name)); }
/// <summary> /// Get a logger by its hash. /// </summary> /// <param name="hash">logger hash</param> /// <returns></returns> internal ILogger this[LoggerHash hash] { get { if (hash == null) { throw new ArgumentNullException("hash"); } return((ILogger)this.v_rankTable[hash]); } }
/// <summary> /// Traverse upwards and notify parents of the newly created logger. /// </summary> /// <param name="log"></param> private void InformParents(Logger log) { string name = log.Name; for (int i = name.LastIndexOf('.'); i >= 0; i = name.Substring(0, i - 1).LastIndexOf('.')) { LoggerHash hash = new LoggerHash(name.Substring(0, i)); Logger parent = this.v_rankTable[hash] as Logger; if (parent != null) { log.Parent = parent; return; } } log.Parent = this.v_mainLogger; }
/// <summary> /// Load configuration into container /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void LoadConfiguration(object sender, EventArgs e) { LoggerContainerImpl container = sender as LoggerContainerImpl; if (container != null) { PropertyHash p = (PropertyHash)container.Configurator.Properties; foreach (object key in p.Keys) { switch (key.ToString()) { case "threshold": this.Threshold = (Level)p[key]; break; case "loggers": IList l = (IList)p[key]; foreach (Object i in l) { ILogger ilogger = i as Logger; if (ilogger != null) { LoggerHash hash = new LoggerHash(ilogger.Name); ((Logger)ilogger).Parent = this.Root; this.v_rankTable[hash] = ilogger; } } break; case "root": ILogger logger = p[key] as ILogger; if (logger != null) { this.Root = (Logger)logger; } break; case "watchConfig": bool value = false; System.Boolean.TryParse(p[key].ToString(), out value); WatchConfig = value; break; } } } }