예제 #1
0
            /// <summary>
            /// set the parent for logger node
            /// </summary>
            /// <param name="parent">logger</param>
            public void WalkAndSetParent(Logger parent)
            {
                if (children == null)
                {
                    return;
                }

                for (int i = 0; i <= children.Count - 1; i++)
                {
                    try
                    {
                        LogNode node = (LogNode)children[i];
                        if (node.logger == null)
                        {
                            node.WalkAndSetParent(parent);
                        }
                        else
                        {
                            DoSetParent(node.logger, parent);
                        }
                    }
                    catch
                    {
                    }
                }
            }
예제 #2
0
        public bool AddLogger(Logger logger)
        {
            string name = logger.GetName();
            //if (string.IsNullOrEmpty(name))
            //    return false;

            Logger old = null;

            if (loggers.ContainsKey(name))
            {
                old = loggers[name];
            }

            if (old != null)
            {
                return(false);
            }


            // We're adding a new logger.
            // Note that we are creating a strong reference here that will
            // keep the Logger in existence indefinitely.
            if (loggers.ContainsKey(name))
            {
                loggers[name] = logger;
            }
            else
            {
                loggers.Add(name, logger);
            }

            //Level level = Level.INFO;
            //logger.SetLevel(level);

            // Find the new node and its parent.
            LogNode node = FindNode(name);

            node.logger = logger;
            Logger  parent = null;
            LogNode nodep  = node.parent;

            while (nodep != null)
            {
                if (nodep.logger != null)
                {
                    parent = nodep.logger;
                    break;
                }
                nodep = nodep.parent;
            }


            if (parent != null)
            {
                DoSetParent(logger, parent);
            }

            node.WalkAndSetParent(logger);
            return(true);
            //Level level = getLevelProperty(name + ".level", null);
        }