예제 #1
0
        public void TestLogEntry()
        {
            DateTime t1 = DateTime.Now;

            _logger.Log(LogLevel.Info, LogMsgFormat, LogMsgArgument);

            _loggerManagement.MessageReceivedEvent.Wait(1000);

            DateTime t2 = DateTime.Now;

            Assert.IsTrue(_loggerManagement.MessageReceivedEvent.IsSet, "No log message received");

            ILogMessage msg = _loggerManagement.Messages.First();

            Assert.IsInstanceOf <LogMessage>(msg);
            Assert.AreEqual(string.Format(LogMsgFormat, LogMsgArgument), msg.Message, "Log message");
            Assert.AreEqual(_logger, msg.Logger, "Logger");
            Assert.AreEqual(_module.GetType().Name, msg.ClassName, "Message class");
            Assert.AreEqual(LogLevel.Info, msg.Level, "Log Level");
            Assert.GreaterOrEqual(msg.Timestamp, t1, "Start of time interval");
            Assert.LessOrEqual(msg.Timestamp, t2, "End of time interval");

            LogMessage internalMsg = (LogMessage)msg;

            Assert.IsFalse(internalMsg.IsException, "IsException");
            Assert.Null(internalMsg.Exception, "Exception");
            Assert.NotNull(internalMsg.LoggerMessage, "LoggerMessage");
            Assert.IsTrue(internalMsg.LoggerMessage.Contains(_module.GetType().Name), "LoggerMessage Classname");
            Assert.IsTrue(internalMsg.LoggerMessage.Contains(string.Format(LogMsgFormat, LogMsgArgument)), "LoggerMessage Content");
        }
예제 #2
0
        public void TestGetChild()
        {
            TestActivateLogging();

            Logger logger = (Logger)_module.Logger;

            IModuleLogger clone = logger.GetChild(null, _module.GetType());

            IModuleLogger childA = logger.GetChild(null);
            IModuleLogger childB = logger.GetChild(null, GetType());
            IModuleLogger childC = logger.GetChild(null, typeof(Object));
            IModuleLogger childD = logger.GetChild(null, typeof(Object));

            Assert.IsTrue(Object.ReferenceEquals(logger, clone), "logger, clone");

            Assert.IsFalse(Object.ReferenceEquals(logger, childA), "logger, childA");
            Assert.IsTrue(Object.ReferenceEquals(childA, childB), "childA, childB");
            Assert.IsFalse(Object.ReferenceEquals(logger, childC), "logger, childC");
            Assert.IsFalse(Object.ReferenceEquals(childA, childC), "childA, childC");
            Assert.IsTrue(Object.ReferenceEquals(childC, childD), "childC, childD");

            IModuleLogger child1 = logger.GetChild("MyChildLogger");
            IModuleLogger child2 = logger.GetChild("MyChildLogger", GetType());
            IModuleLogger child3 = logger.GetChild("MyChildLogger", typeof(Object));
            IModuleLogger child4 = logger.GetChild("MyChildLogger", typeof(Object));
            IModuleLogger child5 = logger.GetChild("MyOtherChildLogger");
            IModuleLogger child6 = logger.GetChild("MyOtherChildLogger", GetType());
            IModuleLogger child7 = logger.GetChild("MyOtherChildLogger", typeof(Object));
            IModuleLogger child8 = logger.GetChild("MyOtherChildLogger", typeof(Object));

            Assert.IsTrue(Object.ReferenceEquals(child1, child2), "child1, child2");
            Assert.IsFalse(Object.ReferenceEquals(child2, child3), "child2, child3");
            Assert.IsTrue(Object.ReferenceEquals(child3, child4), "child3, child4");
            Assert.IsTrue(Object.ReferenceEquals(child5, child6), "child5, child6");
            Assert.IsFalse(Object.ReferenceEquals(child6, child7), "child6, child7");
            Assert.IsTrue(Object.ReferenceEquals(child7, child8), "child7, child8");

            Assert.IsFalse(Object.ReferenceEquals(child1, child5), "child1, child5");
        }