Пример #1
0
        public void CheckNestedThreadVariablesSet()
        {
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            var a = new Log4NetLoggerFactoryAdapter(props);

            bool hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems;

            Assert.AreEqual(false, hasItems);

            a.GetLogger(this.GetType()).NestedThreadVariablesContext.Push("TestValue1");
            a.GetLogger(this.GetType()).NestedThreadVariablesContext.Push("TestValue2");

            hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems;
            Assert.AreEqual(true, hasItems);

            int depth = global::log4net.NDC.Depth;

            Assert.AreEqual(2, depth);

            var actualValue = global::log4net.NDC.Pop();

            Assert.AreEqual("TestValue2", actualValue);

            actualValue = global::log4net.NDC.Pop();
            Assert.AreEqual("TestValue1", actualValue);

            hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems;
            Assert.AreEqual(false, hasItems);

            depth = global::log4net.NDC.Depth;
            Assert.AreEqual(0, depth);
        }
        public void CachesLoggers()
        {
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            Log4NetLoggerFactoryAdapter a = new Log4NetLoggerFactoryAdapter(props);

            ILog log = a.GetLogger(this.GetType());
            Assert.AreSame(log, a.GetLogger(this.GetType()));
        }
Пример #3
0
        public void CachesLoggers()
        {
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            Log4NetLoggerFactoryAdapter a = new Log4NetLoggerFactoryAdapter(props);

            ILog log = a.GetLogger(this.GetType());

            Assert.AreSame(log, a.GetLogger(this.GetType()));
        }
Пример #4
0
        public void CheckThreadVariablesSet()
        {
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            var a = new Log4NetLoggerFactoryAdapter(props);

            a.GetLogger(this.GetType()).ThreadVariablesContext.Set("TestKey", "TestValue");

            var actualValue = global::log4net.ThreadContext.Properties["TestKey"];

            Assert.AreEqual("TestValue", actualValue);
        }
        public void CheckThreadVariablesSet()
        {
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            var a = new Log4NetLoggerFactoryAdapter(props);

            a.GetLogger(this.GetType()).ThreadVariablesContext.Set("TestKey", "TestValue");

            var actualValue = global::log4net.ThreadContext.Properties["TestKey"];

            Assert.AreEqual("TestValue", actualValue);
        }
        public void TestSetUp()
        {
            _log4NetLoggerFactoryAdapter = new Log4NetLoggerFactoryAdapter(new NameValueCollection());
            _nLogLoggerFactoryAdapter = new NLogLoggerFactoryAdapter(new NameValueCollection());
            _multipleLoggerFactoryAdapter = new MultiLoggerFactoryAdapter();

            _multipleLoggerFactoryAdapter.LoggerFactoryAdapters.Add(_log4NetLoggerFactoryAdapter);
            _multipleLoggerFactoryAdapter.LoggerFactoryAdapters.Add(_nLogLoggerFactoryAdapter);

            //these tests will only work if all of the loggers actually *support* VariablesContext with other than the No-Op 'placeholder'
            Assume.That(_log4NetLoggerFactoryAdapter.GetLogger(typeof(MultipleLoggerGlobalVariableContextTests)).GlobalVariablesContext, Is.Not.InstanceOf<NoOpVariablesContext>());
            Assume.That(_nLogLoggerFactoryAdapter.GetLogger(typeof(MultipleLoggerGlobalVariableContextTests)).GlobalVariablesContext, Is.Not.InstanceOf<NoOpVariablesContext>());
        }
        public void LogsCorrectLoggerName()
        {
            TestAppender testAppender = new TestAppender();

            BasicConfigurator.Configure(testAppender);

            Log4NetLoggerFactoryAdapter a;
            NameValueCollection         props = new NameValueCollection();

            props["configType"] = "external";
            a = new Log4NetLoggerFactoryAdapter(props);

            a.GetLogger(this.GetType()).Debug("TestMessage");

            Assert.AreEqual(this.GetType().FullName, testAppender.LastLoggingEvent.GetLoggingEventData().LoggerName);
            Assert.AreEqual("TestMessage", testAppender.LastLoggingEvent.MessageObject);
        }
        public void LogsCorrectLoggerName()
        {
            TestAppender testAppender = new TestAppender();
            BasicConfigurator.Configure(testAppender);

            Log4NetLoggerFactoryAdapter a;
            NameValueCollection props = new NameValueCollection();

            props["configType"] = "external";
            a = new Log4NetLoggerFactoryAdapter(props);

            a.GetLogger(this.GetType()).Debug("TestMessage");

            Assert.AreEqual(this.GetType().FullName, testAppender.LastLoggingEvent.GetLoggingEventData().LoggerName);
            Assert.AreEqual(this.GetType().FullName, testAppender.LastLoggingEvent.LocationInformation.ClassName);
            Assert.AreEqual(MethodBase.GetCurrentMethod().Name, testAppender.LastLoggingEvent.LocationInformation.MethodName);
            Assert.AreEqual("TestMessage", testAppender.LastLoggingEvent.MessageObject);
        }