예제 #1
0
        public void InternalMessageTest()
        {
            try {
                LogInternal.InternalMessage = false;
                LogInternal.InternalDebug   = true;

                XmlDocument log4netConfig = new XmlDocument();
                log4netConfig.LoadXml(@"
                <Soyo.Base.Log>
                  <appender name=""LogLogAppender"" type=""UnitTest.Base.Log.LoggerRepository.LogLogAppender"">
                    <layout type=""Soyo.Base.Text.LayoutLoggerSimple"" />
                  </appender>
                  <appender name=""AppenderMemory"" type=""Soyo.Base.Text.AppenderMemory"">
                    <layout type=""Soyo.Base.Text.LayoutLoggerSimple"" />
                  </appender>
                  <root>
                    <level value=""ALL"" />
                    <appender-ref ref=""LogLogAppender"" />
                    <appender-ref ref=""AppenderMemory"" />
                  </root>  
                </Soyo.Base.Log>");

                ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());
                rep.ChangeConfigEvent += new LoggerControllerEventHandler(rep_ConfigurationChanged);

                ICollection <LogInternal> configurationMessages = XmlConfig.Config(rep, log4netConfig["Soyo.Base.Log"]);

                Assert.IsTrue(configurationMessages.Count > 0);
            } finally {
                LogInternal.InternalMessage = true;
                LogInternal.InternalDebug   = false;
            }
        }
        public void SetControllerPropertiesInXmlFile()
        {
            // LOG4NET-53: Allow repository properties to be set in the config file
            XmlDocument log4netConfig = new XmlDocument();

            log4netConfig.LoadXml(@"
                <Soyo.Base.Log>
                  <property>
                    <key value=""two-plus-two"" />
                    <value value=""4"" />
                  </property>
                  <appender name=""StringAppender"" type=""UnitTest.Base.Log.StringAppender"">
                    <layout type=""Soyo.Base.Text.LayoutLoggerSimple"" />
                  </appender>
                  <root>
                    <level value=""ALL"" />
                    <appender-ref ref=""StringAppender"" />
                  </root>
                </Soyo.Base.Log>");

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            XmlConfig.Config(rep, log4netConfig["Soyo.Base.Log"]);

            Assert.AreEqual("4", rep.PropertySet["two-plus-two"]);
            Assert.IsNull(rep.PropertySet["one-plus-one"]);
        }
        public void PatternConverterProperties()
        {
            XmlDocument log4netConfig = new XmlDocument();

            log4netConfig.LoadXml(@"
                <Soyo.Base.Log>
                  <appender name=""PatternStringAppender"" type=""UnitTest.Base.Log.PatternStringAppender"">
                    <layout type=""Soyo.Base.Text.LayoutLoggerSimple"" />
                    <setting>
                        <converter>
                            <name value=""propertyKeyCount"" />
                            <type value=""UnitTest.Base.Log.PropertyKeyCountPatternConverter"" />
                            <property>
                                <key value=""one-plus-one"" />
                                <value value=""2"" />
                            </property>
                            <property>
                               <key value=""two-plus-two"" />
                               <value value=""4"" />
                            </property> 
                        </converter>
                        <pattern value=""%propertyKeyCount"" />
                    </setting>
                  </appender>
                  <root>
                    <level value=""ALL"" />                  
                    <appender-ref ref=""PatternStringAppender"" />
                  </root>  
                </Soyo.Base.Log>");

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            XmlConfig.Config(rep, log4netConfig["Soyo.Base.Log"]);

            ILog log = LogManager.Get(rep.Name, "PatternConverterProperties");

            log.Debug("Message");

            PropertyKeyCountPatternConverter converter =
                PropertyKeyCountPatternConverter.MostRecentInstance;

            Assert.AreEqual(2, converter.PropertySet.Count);
            Assert.AreEqual("4", converter.PropertySet["two-plus-two"]);

            PatternStringAppender appender =
                (PatternStringAppender)LogManager.GetController(rep.Name).AppenderSet[0];

            Assert.AreEqual("2", appender.Setting.Format());
        }
예제 #4
0
        public void FilterConfigurationTest()
        {
            XmlDocument log4netConfig = new XmlDocument();

            #region Load log4netConfig
            log4netConfig.LoadXml(@"
            <Soyo.Base.Log>
            <appender name=""AppenderMemory"" type=""Soyo.Base.Text.AppenderMemory"">
                <filter type=""UnitTest.Base.Log.MultiplePropertyFilter"">
                    <condition>
                        <key value=""ABC"" />
                        <stringToMatch value=""123"" />
                    </condition>
                    <condition>
                        <key value=""DEF"" />
                        <stringToMatch value=""456"" />
                    </condition>
                </filter>
            </appender>
            <root>
                <level value=""ALL"" />
                <appender-ref ref=""AppenderMemory"" />
            </root>
            </Soyo.Base.Log>");
            #endregion

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());
            XmlConfig.Config(rep, log4netConfig["Soyo.Base.Log"]);

            IAppender[] appenders = LogManager.GetController(rep.Name).AppenderSet;
            Assert.IsTrue(appenders.Length == 1);

            IAppender appender = Array.Find(appenders, delegate(IAppender a) {
                return(a.Name == "AppenderMemory");
            });
            Assert.IsNotNull(appender);

            MultiplePropertyFilter multiplePropertyFilter =
                ((AppenderBase)appender).FilterHead as MultiplePropertyFilter;

            MultiplePropertyFilter.Condition[] conditions = multiplePropertyFilter.GetConditions();
            Assert.AreEqual(2, conditions.Length);
            Assert.AreEqual("ABC", conditions[0].Key);
            Assert.AreEqual("123", conditions[0].StringToMatch);
            Assert.AreEqual("DEF", conditions[1].Key);
            Assert.AreEqual("456", conditions[1].StringToMatch);
        }
        // LOG4NET-343
        public void LoggerNameCanConsistOfASingleDot()
        {
            XmlDocument log4netConfig = new XmlDocument();

            log4netConfig.LoadXml(@"
                <Soyo.Base.Log>
                  <appender name=""StringAppender"" type=""UnitTest.Base.Log.StringAppender"">
                    <layout type=""Soyo.Base.Text.LayoutLoggerSimple"" />
                  </appender>
                  <root>
                    <level value=""ALL"" />
                    <appender-ref ref=""StringAppender"" />
                  </root>
                  <logger name=""."">
                    <level value=""WARN"" />
                  </logger>
                </Soyo.Base.Log>");

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            XmlConfig.Config(rep, log4netConfig["Soyo.Base.Log"]);
        }