/// <summary> /// Updates all the parents of the specified logger. /// </summary> /// <param name="log">The logger to update the parents for.</param> /// <remarks> /// <para> /// This method loops through all the <i>potential</i> parents of /// <paramref name="log"/>. There 3 possible cases: /// </para> /// <list type="number"> /// <item> /// <term>No entry for the potential parent of <paramref name="log"/> exists</term> /// <description> /// We create a ProvisionNode for this potential /// parent and insert <paramref name="log"/> in that provision node. /// </description> /// </item> /// <item> /// <term>The entry is of type Logger for the potential parent.</term> /// <description> /// The entry is <paramref name="log"/>'s nearest existing parent. We /// update <paramref name="log"/>'s parent field with this entry. We also break from /// he loop because updating our parent's parent is our parent's /// responsibility. /// </description> /// </item> /// <item> /// <term>The entry is of type ProvisionNode for this potential parent.</term> /// <description> /// We add <paramref name="log"/> to the list of children for this /// potential parent. /// </description> /// </item> /// </list> /// </remarks> private void UpdateParents(Logger log) { string name = log.Name; int length = name.Length; bool parentFound = false; // if name = "w.x.y.z", loop through "w.x.y", "w.x" and "w", but not "w.x.y.z" for (int i = name.LastIndexOf('.', length - 1); i >= 0; i = name.LastIndexOf('.', i - 1)) { string substr = name.Substring(0, i); LoggerKey key = new LoggerKey(substr); // simple constructor object node = this.m_ht[key]; // Create a provision node for a future parent. if (node == null) { ProvisionNode pn = new ProvisionNode(log); this.m_ht[key] = pn; } else { Logger nodeLogger = node as Logger; if (nodeLogger != null) { parentFound = true; log.Parent = nodeLogger; break; // no need to update the ancestors of the closest ancestor } else { ProvisionNode nodeProvisionNode = node as ProvisionNode; if (nodeProvisionNode != null) { nodeProvisionNode.Add(log); } else { LogLog.Error(declaringType, "Unexpected object type [" + node.GetType() + "] in ht.", new LogException()); } } } if (i == 0) { // logger name starts with a dot // and we've hit the start break; } } // If we could not find any existing parents, then link with root. if (!parentFound) { log.Parent = this.Root; } }
public Logger GetLogger(string name, ILoggerFactory factory) { Logger logger2; if (name == null) { throw new ArgumentNullException("name"); } if (factory == null) { throw new ArgumentNullException("factory"); } LoggerKey key = new LoggerKey(name); lock (this.m_ht) { Logger log = null; object obj3 = this.m_ht[key]; if (obj3 == null) { log = factory.CreateLogger(this, name); log.Hierarchy = this; this.m_ht[key] = log; this.UpdateParents(log); this.OnLoggerCreationEvent(log); logger2 = log; } else { Logger logger3 = obj3 as Logger; if (logger3 != null) { logger2 = logger3; } else { ProvisionNode pn = obj3 as ProvisionNode; if (pn == null) { logger2 = null; } else { log = factory.CreateLogger(this, name); log.Hierarchy = this; this.m_ht[key] = log; UpdateChildren(pn, log); this.UpdateParents(log); this.OnLoggerCreationEvent(log); logger2 = log; } } } } return(logger2); }
/// <summary> /// Return a new logger instance named as the first parameter using /// <paramref name="factory"/>. /// </summary> /// <param name="name">The name of the logger to retrieve</param> /// <param name="factory">The factory that will make the new logger instance</param> /// <returns>The logger object with the name specified</returns> /// <remarks> /// <para> /// If a logger of that name already exists, then it will be /// returned. Otherwise, a new logger will be instantiated by the /// <paramref name="factory"/> parameter and linked with its existing /// ancestors as well as children. /// </para> /// </remarks> public Logger GetLogger(string name, ILoggerFactory factory) { if (name == null) { throw new ArgumentNullException("name"); } if (factory == null) { throw new ArgumentNullException("factory"); } LoggerKey key = new LoggerKey(name); // Synchronize to prevent write conflicts. Read conflicts (in // GetEffectiveLevel() method) are possible only if variable // assignments are non-atomic. lock (m_ht) { Logger logger = null; Object node = m_ht[key]; if (node == null) { logger = factory.CreateLogger(this, name); logger.Hierarchy = this; m_ht[key] = logger; UpdateParents(logger); OnLoggerCreationEvent(logger); return(logger); } Logger nodeLogger = node as Logger; if (nodeLogger != null) { return(nodeLogger); } ProvisionNode nodeProvisionNode = node as ProvisionNode; if (nodeProvisionNode != null) { logger = factory.CreateLogger(this, name); logger.Hierarchy = this; m_ht[key] = logger; UpdateChildren(nodeProvisionNode, logger); UpdateParents(logger); OnLoggerCreationEvent(logger); return(logger); } // It should be impossible to arrive here but let's keep the compiler happy. return(null); } }
private static void UpdateChildren(ProvisionNode pn, Logger log) { for (int i = 0; i < pn.Count; i++) { Logger logger = (Logger)pn[i]; if (!logger.Parent.Name.StartsWith(log.Name)) { log.Parent = logger.Parent; logger.Parent = log; } } }
/// <summary> /// Updates all the parents of the specified logger /// </summary> /// <param name="log">The logger to update the parents for</param> /// <remarks> /// <para> /// This method loops through all the <i>potential</i> parents of /// <paramref name="log"/>. There 3 possible cases: /// </para> /// <list type="number"> /// <item> /// <term>No entry for the potential parent of <paramref name="log"/> exists</term> /// <description> /// We create a ProvisionNode for this potential /// parent and insert <paramref name="log"/> in that provision node. /// </description> /// </item> /// <item> /// <term>The entry is of type Logger for the potential parent.</term> /// <description> /// The entry is <paramref name="log"/>'s nearest existing parent. We /// update <paramref name="log"/>'s parent field with this entry. We also break from /// he loop because updating our parent's parent is our parent's /// responsibility. /// </description> /// </item> /// <item> /// <term>The entry is of type ProvisionNode for this potential parent.</term> /// <description> /// We add <paramref name="log"/> to the list of children for this /// potential parent. /// </description> /// </item> /// </list> /// </remarks> void UpdateParents(Logger log) { var name = log.Name; var length = name.Length; var parentFound = false; // if name = "w.x.y.z", loop through "w.x.y", "w.x" and "w", but not "w.x.y.z" for (var i = name.LastIndexOf('.', length - 1); i >= 0; i = name.LastIndexOf('.', i - 1)) { var substr = name.Substring(0, i); var key = new LoggerKey(substr); // simple constructor var node = m_ht[key]; // Create a provision node for a future parent. if (node == null) { var pn = new ProvisionNode(log); m_ht[key] = pn; } else { var nodeLogger = node as Logger; if (nodeLogger != null) { parentFound = true; log.Parent = nodeLogger; break; // no need to update the ancestors of the closest ancestor } else { var nodeProvisionNode = node as ProvisionNode; if (nodeProvisionNode != null) { nodeProvisionNode.Add(log); } else { LogLog.Error("Hierarchy: Unexpected object type [" + node.GetType() + "] in ht.", new LogException()); } } } } // If we could not find any existing parents, then link with root. if (!parentFound) { log.Parent = Root; } }
/// <summary> /// Replace a <see cref="ProvisionNode"/> with a <see cref="Logger"/> in the hierarchy. /// </summary> /// <param name="pn"></param> /// <param name="log"></param> /// <remarks> /// <para> /// We update the links for all the children that placed themselves /// in the provision node 'pn'. The second argument 'log' is a /// reference for the newly created Logger, parent of all the /// children in 'pn'. /// </para> /// <para> /// We loop on all the children 'c' in 'pn'. /// </para> /// <para> /// If the child 'c' has been already linked to a child of /// 'log' then there is no need to update 'c'. /// </para> /// <para> /// Otherwise, we set log's parent field to c's parent and set /// c's parent field to log. /// </para> /// </remarks> private static void UpdateChildren(ProvisionNode pn, Logger log) { for (int i = 0; i < pn.Count; i++) { Logger childLogger = (Logger)pn[i]; // Unless this child already points to a correct (lower) parent, // make log.Parent point to childLogger.Parent and childLogger.Parent to log. if (!childLogger.Parent.Name.StartsWith(log.Name)) { log.Parent = childLogger.Parent; childLogger.Parent = log; } } }
/// <summary> /// Updates all the parents of the specified logger /// </summary> /// <param name="log">The logger to update the parents for</param> /// <remarks> /// <para> /// This method loops through all the <i>potential</i> parents of /// <paramref name="log" />. There 3 possible cases: /// </para> /// <list type="number"> /// <item> /// <term>No entry for the potential parent of <paramref name="log" /> exists</term> /// <description> /// We create a ProvisionNode for this potential /// parent and insert <paramref name="log" /> in that provision node. /// </description> /// </item> /// <item> /// <term>The entry is of type Logger for the potential parent.</term> /// <description> /// The entry is <paramref name="log" />'s nearest existing parent. We /// update <paramref name="log" />'s parent field with this entry. We also break from /// he loop because updating our parent's parent is our parent's /// responsibility. /// </description> /// </item> /// <item> /// <term>The entry is of type ProvisionNode for this potential parent.</term> /// <description> /// We add <paramref name="log" /> to the list of children for this /// potential parent. /// </description> /// </item> /// </list> /// </remarks> private void UpdateParents(Logger log) { string name = log.Name; int length = name.Length; bool flag = false; for (int num = name.LastIndexOf('.', length - 1); num >= 0; num = name.LastIndexOf('.', num - 1)) { LoggerKey key = new LoggerKey(name.Substring(0, num)); object obj = m_ht[key]; if (obj == null) { ProvisionNode value = new ProvisionNode(log); m_ht[key] = value; } else { Logger logger = obj as Logger; if (logger != null) { flag = true; log.Parent = logger; break; } ProvisionNode provisionNode = obj as ProvisionNode; if (provisionNode != null) { provisionNode.Add(log); } else { LogLog.Error(declaringType, "Unexpected object type [" + obj.GetType() + "] in ht.", new LogException()); } } if (num == 0) { break; } } if (!flag) { log.Parent = Root; } }
/// <summary> /// Return a new logger instance named as the first parameter using /// <paramref name="factory" />. /// </summary> /// <param name="name">The name of the logger to retrieve</param> /// <param name="factory">The factory that will make the new logger instance</param> /// <returns>The logger object with the name specified</returns> /// <remarks> /// <para> /// If a logger of that name already exists, then it will be /// returned. Otherwise, a new logger will be instantiated by the /// <paramref name="factory" /> parameter and linked with its existing /// ancestors as well as children. /// </para> /// </remarks> public Logger GetLogger(string name, ILoggerFactory factory) { if (name == null) { throw new ArgumentNullException("name"); } if (factory == null) { throw new ArgumentNullException("factory"); } LoggerKey key = new LoggerKey(name); lock (m_ht) { Logger logger = null; object obj = m_ht[key]; if (obj == null) { logger = factory.CreateLogger(this, name); logger.Hierarchy = this; m_ht[key] = logger; UpdateParents(logger); OnLoggerCreationEvent(logger); return(logger); } Logger logger2 = obj as Logger; if (logger2 != null) { return(logger2); } ProvisionNode provisionNode = obj as ProvisionNode; if (provisionNode != null) { logger = factory.CreateLogger(this, name); logger.Hierarchy = this; m_ht[key] = logger; UpdateChildren(provisionNode, logger); UpdateParents(logger); OnLoggerCreationEvent(logger); return(logger); } return(null); } }
private void UpdateParents(Logger log) { string name = log.Name; bool flag = false; for (int i = name.LastIndexOf('.', name.Length - 1); i >= 0; i = name.LastIndexOf('.', i - 1)) { string str2 = name.Substring(0, i); LoggerKey key = new LoggerKey(str2); object obj2 = this.m_ht[key]; if (obj2 == null) { this.m_ht[key] = new ProvisionNode(log); } else { Logger logger = obj2 as Logger; if (logger != null) { flag = true; log.Parent = logger; break; } ProvisionNode node2 = obj2 as ProvisionNode; if (node2 != null) { node2.Add(log); } else { LogLog.Error(declaringType, "Unexpected object type [" + obj2.GetType() + "] in ht.", new LogException()); } } if (i == 0) { break; } } if (!flag) { log.Parent = this.Root; } }
/// <summary> /// Updates all the parents of the specified logger /// </summary> /// <remarks> /// This method loops through all the <i>potential</i> parents of /// 'log'. There 3 possible cases: /// <list type="number"> /// <item> /// <term>No entry for the potential parent of 'log' exists</term> /// <description>We create a ProvisionNode for this potential /// parent and insert 'log' in that provision node.</description> /// </item> /// <item> /// <term>There entry is of type Logger for the potential parent.</term> /// <description>The entry is 'log's nearest existing parent. We /// update log's parent field with this entry. We also break from /// he loop because updating our parent's parent is our parent's /// responsibility.</description> /// </item> /// <item> /// <term>There entry is of type ProvisionNode for this potential parent.</term> /// <description>We add 'log' to the list of children for this /// potential parent.</description> /// </item> /// </list> /// </remarks> /// <param name="log">The logger to update the parents for</param> private void UpdateParents(Logger log) { string name = log.Name; int length = name.Length; bool parentFound = false; // if name = "w.x.y.z", loop through "w.x.y", "w.x" and "w", but not "w.x.y.z" for (int i = name.LastIndexOf('.', length - 1); i >= 0; i = name.LastIndexOf('.', i - 1)) { string substr = name.Substring(0, i); LoggerKey key = new LoggerKey(substr); // simple constructor Object node = m_ht[key]; // Create a provision node for a future parent. if (node == null) { ProvisionNode pn = new ProvisionNode(log); m_ht[key] = pn; } else if (node is Logger) { parentFound = true; log.Parent = (Logger)node; break; // no need to update the ancestors of the closest ancestor } else if (node is ProvisionNode) { ((ProvisionNode)node).Add(log); } else { LogLog.Error("unexpected object type [" + node.GetType() + "] in ht.", new LogException()); } } // If we could not find any existing parents, then link with root. if (!parentFound) { log.Parent = m_root; } }
/// <summary> /// Replace a <see cref="ProvisionNode"/> with a <see cref="Logger"/> in the hierarchy. /// </summary> /// <param name="pn"></param> /// <param name="log"></param> /// <remarks> /// <para> /// We update the links for all the children that placed themselves /// in the provision node 'pn'. The second argument 'log' is a /// reference for the newly created Logger, parent of all the /// children in 'pn'. /// </para> /// <para> /// We loop on all the children 'c' in 'pn'. /// </para> /// <para> /// If the child 'c' has been already linked to a child of /// 'log' then there is no need to update 'c'. /// </para> /// <para> /// Otherwise, we set log's parent field to c's parent and set /// c's parent field to log. /// </para> /// </remarks> private void UpdateChildren(ProvisionNode pn, Logger log) { for(int i = 0; i < pn.Count; i++) { Logger childLogger = (Logger)pn[i]; // Unless this child already points to a correct (lower) parent, // make log.Parent point to childLogger.Parent and childLogger.Parent to log. if (!childLogger.Parent.Name.StartsWith(log.Name)) { log.Parent = childLogger.Parent; childLogger.Parent = log; } } }
/// <summary> /// Updates all the parents of the specified logger /// </summary> /// <param name="log">The logger to update the parents for</param> /// <remarks> /// <para> /// This method loops through all the <i>potential</i> parents of /// <paramref name="log"/>. There 3 possible cases: /// </para> /// <list type="number"> /// <item> /// <term>No entry for the potential parent of <paramref name="log"/> exists</term> /// <description> /// We create a ProvisionNode for this potential /// parent and insert <paramref name="log"/> in that provision node. /// </description> /// </item> /// <item> /// <term>The entry is of type Logger for the potential parent.</term> /// <description> /// The entry is <paramref name="log"/>'s nearest existing parent. We /// update <paramref name="log"/>'s parent field with this entry. We also break from /// he loop because updating our parent's parent is our parent's /// responsibility. /// </description> /// </item> /// <item> /// <term>The entry is of type ProvisionNode for this potential parent.</term> /// <description> /// We add <paramref name="log"/> to the list of children for this /// potential parent. /// </description> /// </item> /// </list> /// </remarks> private void UpdateParents(Logger log) { string name = log.Name; int length = name.Length; bool parentFound = false; // if name = "w.x.y.z", loop through "w.x.y", "w.x" and "w", but not "w.x.y.z" for(int i = name.LastIndexOf('.', length-1); i >= 0; i = name.LastIndexOf('.', i-1)) { string substr = name.Substring(0, i); LoggerKey key = new LoggerKey(substr); // simple constructor Object node = m_ht[key]; // Create a provision node for a future parent. if (node == null) { ProvisionNode pn = new ProvisionNode(log); m_ht[key] = pn; } else { Logger nodeLogger = node as Logger; if (nodeLogger != null) { parentFound = true; log.Parent = nodeLogger; break; // no need to update the ancestors of the closest ancestor } else { ProvisionNode nodeProvisionNode = node as ProvisionNode; if (nodeProvisionNode != null) { nodeProvisionNode.Add(log); } else { LogLog.Error("Hierarchy: Unexpected object type ["+node.GetType()+"] in ht.", new LogException()); } } } } // If we could not find any existing parents, then link with root. if (!parentFound) { log.Parent = this.Root; } }