public void ShouldLogSingleEvent() { ILogger logger = hierarchy.GetLogger("test"); logger.Log(GetType(), Level.Warn, "foo", null); string log = WaitSomeTimeAndReturnLogWithLineFeedsStripped(); Assert.AreEqual("WARN - foo", log); }
public void Test1() { Assert.AreEqual(0, _countingAppender.Counter, "Test empty appender"); var logger = _hierarchy.GetLogger("test"); logger.Log(typeof(HttpRequestAppenderTests), Level.Warn, "Message logged", null); Assert.AreEqual(1, _countingAppender.Counter); }
public void TestSetupAppender() { SetupRepository(); Assert.AreEqual(0, m_countingAppender.Counter, "Test empty appender"); ILogger logger = m_hierarchy.GetLogger("test"); logger.Log(typeof(BufferingAppenderTest), Level.Warn, "Message logged", null); Assert.AreEqual(1, m_countingAppender.Counter, "Test 1 event logged"); }
public void TestHierarchy1() { Repository.Hierarchy.Hierarchy h = new Repository.Hierarchy.Hierarchy(); h.Root.Level = Level.Error; Logger a0 = (Logger)h.GetLogger("a"); Assert.AreEqual("a", a0.Name); Assert.IsNull(a0.Level); Assert.AreSame(Level.Error, a0.EffectiveLevel); Logger a1 = (Logger)h.GetLogger("a"); Assert.AreSame(a0, a1); }
public void TestLevelEvaluator() { m_bufferingForwardingAppender.Evaluator = new LevelEvaluator(Level.Info); m_bufferingForwardingAppender.ActivateOptions(); log4net.Config.BasicConfigurator.Configure(m_hierarchy, m_bufferingForwardingAppender); ILogger logger = m_hierarchy.GetLogger("TestLevelEvaluator"); logger.Log(typeof(EvaluatorTest), Level.Debug, "Debug message logged", null); logger.Log(typeof(EvaluatorTest), Level.Debug, "Debug message logged", null); Assert.AreEqual(0, m_countingAppender.Counter, "Test 2 events buffered"); logger.Log(typeof(EvaluatorTest), Level.Info, "Info message logged", null); Assert.AreEqual(3, m_countingAppender.Counter, "Test 3 events flushed on Info message."); }
private void SetupRepository() { m_hierarchy = new Repository.Hierarchy.Hierarchy(); m_eventRaisingAppender = new EventRaisingAppender(); m_eventRaisingAppender.LoggingEventAppended += eventRaisingAppender_LoggingEventAppended; m_hierarchy.Root.Level = Level.All; m_hierarchy.Root.AddAppender(m_eventRaisingAppender); BasicConfigurator.Configure(m_hierarchy, m_eventRaisingAppender); m_logger = m_hierarchy.GetLogger("test"); }
/// <summary> /// Creates a logger hierarchy, configures a SMTP pickup dir appender and returns an ILogger /// </summary> /// <param name="appender">The appender to use</param> /// <returns>A configured ILogger</returns> private ILogger CreateLogger(SmtpPickupDirAppender appender) { Repository.Hierarchy.Hierarchy h = (Repository.Hierarchy.Hierarchy)LogManager.CreateRepository("TestRepository"); PatternLayout layout = new PatternLayout(); layout.ConversionPattern = "%m%n"; layout.ActivateOptions(); appender.Layout = layout; appender.ActivateOptions(); h.Root.AddAppender(appender); h.Configured = true; ILogger log = h.GetLogger("Logger"); return(log); }