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(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)
        {
            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);
            }
        }
        override public bool Equals(object obj)
        {
            // Compare reference type of this against argument
            if (((object)this) == obj)
            {
                return(true);
            }

            LoggerKey objKey = obj as LoggerKey;

            if (objKey != null)
            {
                return(((object)m_name) == ((object)objKey.m_name));
            }
            return(false);
        }