예제 #1
0
        /// <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;
            }
        }
예제 #2
0
        /// <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;
            }
        }
예제 #3
0
        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;
            }
        }