Exemplo n.º 1
0
 /// <summary>
 /// Destroys the logger hierarchy created by <see cref="SmtpPickupDirAppenderTest.CreateLogger"/>
 /// </summary>
 private static void DestroyLogger()
 {
     Repository.Hierarchy.Hierarchy h = (Repository.Hierarchy.Hierarchy)LogManager.GetRepository("TestRepository");
     h.ResetConfiguration();
     //Replace the repository selector so that we can recreate the hierarchy with the same name if necessary
     LoggerManager.RepositorySelector = new DefaultRepositorySelector(typeof(log4net.Repository.Hierarchy.Hierarchy));
 }
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
        private static void ExecuteBackgroundThread()
        {
            ILog log = LogManager.GetLogger(TestBackgroundThreadContextPropertyRepository, "ExecuteBackGroundThread");

            ThreadContext.Properties["DateTimeTodayToString"] = DateTime.Today.ToString();

            log.Info("TestMessage");

            Repository.Hierarchy.Hierarchy hierarchyLoggingRepository = (Repository.Hierarchy.Hierarchy)log.Logger.Repository;
            StringAppender stringAppender = (StringAppender)hierarchyLoggingRepository.Root.Appenders[0];

            Assert.AreEqual(DateTime.Today.ToString(), stringAppender.GetString());
        }
Exemplo n.º 4
0
        public void SetupRepository()
        {
            hierarchy = new Repository.Hierarchy.Hierarchy();

            stringAppender        = new StringAppender();
            stringAppender.Layout = new SimpleLayout();
            stringAppender.ActivateOptions();

            asyncAppender = new AsyncAppender();
            asyncAppender.AddAppender(stringAppender);
            asyncAppender.ActivateOptions();

            BasicConfigurator.Configure(hierarchy, asyncAppender);
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        public void SetupRepository()
        {
            hierarchy = new Repository.Hierarchy.Hierarchy();

            stringAppender = new StringAppender();
            stringAppender.Layout = new SimpleLayout();
            stringAppender.ActivateOptions();

            asyncAppender = new AsyncAppender();
            asyncAppender.AddAppender(stringAppender);
            asyncAppender.ActivateOptions();

            BasicConfigurator.Configure(hierarchy, asyncAppender);
        }
Exemplo n.º 7
0
        public void TestDisable1()
        {
            CountingAppender caRoot = new CountingAppender();
            Logger           root   = ((Repository.Hierarchy.Hierarchy)Utils.GetRepository()).Root;

            root.AddAppender(caRoot);

            Repository.Hierarchy.Hierarchy h = ((Repository.Hierarchy.Hierarchy)Utils.GetRepository());
            h.Threshold  = Level.Info;
            h.Configured = true;

            Assert.AreEqual(caRoot.Counter, 0);

            root.Log(Level.Debug, MSG, null);
            Assert.AreEqual(caRoot.Counter, 0);
            root.Log(Level.Info, MSG, null);
            Assert.AreEqual(caRoot.Counter, 1);
            root.Log(Level.Warn, MSG, null);
            Assert.AreEqual(caRoot.Counter, 2);
            root.Log(Level.Warn, MSG, null);
            Assert.AreEqual(caRoot.Counter, 3);

            h.Threshold = Level.Warn;
            root.Log(Level.Debug, MSG, null);
            Assert.AreEqual(caRoot.Counter, 3);
            root.Log(Level.Info, MSG, null);
            Assert.AreEqual(caRoot.Counter, 3);
            root.Log(Level.Warn, MSG, null);
            Assert.AreEqual(caRoot.Counter, 4);
            root.Log(Level.Error, MSG, null);
            Assert.AreEqual(caRoot.Counter, 5);
            root.Log(Level.Error, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);

            h.Threshold = Level.Off;
            root.Log(Level.Debug, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
            root.Log(Level.Info, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
            root.Log(Level.Warn, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
            root.Log(Level.Error, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
            root.Log(Level.Fatal, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
            root.Log(Level.Fatal, MSG, null);
            Assert.AreEqual(caRoot.Counter, 6);
        }
        public void SetupRepository()
        {
            m_hierarchy = new Repository.Hierarchy.Hierarchy();

            m_countingAppender = new CountingAppender();
            m_countingAppender.ActivateOptions();

            m_bufferingForwardingAppender = new BufferingForwardingAppender();
            m_bufferingForwardingAppender.AddAppender(m_countingAppender);

            m_bufferingForwardingAppender.BufferSize = 5;
            m_bufferingForwardingAppender.ClearFilters();
            m_bufferingForwardingAppender.Fix            = FixFlags.Partial;
            m_bufferingForwardingAppender.Lossy          = false;
            m_bufferingForwardingAppender.LossyEvaluator = null;
            m_bufferingForwardingAppender.Threshold      = Level.All;
        }
Exemplo n.º 9
0
		public void SetupRepository()
		{
			m_hierarchy = new Repository.Hierarchy.Hierarchy();

			m_countingAppender = new CountingAppender();
			m_countingAppender.ActivateOptions();

			m_bufferingForwardingAppender = new BufferingForwardingAppender();
			m_bufferingForwardingAppender.AddAppender(m_countingAppender);

			m_bufferingForwardingAppender.BufferSize = 5;
			m_bufferingForwardingAppender.ClearFilters();
			m_bufferingForwardingAppender.Fix = FixFlags.Partial;
			m_bufferingForwardingAppender.Lossy = false;
			m_bufferingForwardingAppender.LossyEvaluator = null;
			m_bufferingForwardingAppender.Threshold = Level.All;
		}
Exemplo n.º 10
0
        public void SetupRepository()
        {
            _hierarchy = new Repository.Hierarchy.Hierarchy();

            _countingAppender = new CountingAppender();
            _countingAppender.ActivateOptions();

            _httpRequestAppender = new HttpRequestAppenderStub();
            _httpRequestAppender.AddAppender(_countingAppender);

            _httpRequestAppender.ClearFilters();
            _httpRequestAppender.Threshold = Level.All;
            _httpRequestAppender.Layout    = new SimpleLayout();

            _httpRequestAppender.ActivateOptions();

            BasicConfigurator.Configure(_hierarchy, _httpRequestAppender);
        }
Exemplo n.º 11
0
        public void AddingMultipleAppenders()
        {
            CountingAppender alpha = new CountingAppender();
            CountingAppender beta  = new CountingAppender();

            Repository.Hierarchy.Hierarchy hierarchy =
                (Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
            hierarchy.Root.AddAppender(alpha);
            hierarchy.Root.AddAppender(beta);
            hierarchy.Configured = true;

            ILog log = LogManager.GetLogger(GetType());

            log.Debug("Hello World");

            Assert.AreEqual(1, alpha.Counter);
            Assert.AreEqual(1, beta.Counter);
        }
        public void SetupRepository()
        {
            _hierarchy = new Repository.Hierarchy.Hierarchy();

            _countingAppender = new CountingAppender();
            _countingAppender.ActivateOptions();

            _httpRequestAppender = new HttpRequestAppenderStub();
            _httpRequestAppender.AddAppender(_countingAppender);

            _httpRequestAppender.ClearFilters();
            _httpRequestAppender.Threshold = Level.All;
            _httpRequestAppender.Layout = new SimpleLayout();

            _httpRequestAppender.ActivateOptions();

            BasicConfigurator.Configure(_hierarchy, _httpRequestAppender);
        }
Exemplo n.º 13
0
        /// <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);
        }