示例#1
0
        public void FilterAddIDTest()
        {
            LogItem message = new LogItem(category, level, msg, ids, GetException());
             var qThread = new Mock<IQueued<LogItem>>(MockBehavior.Strict);
             var writer = new Mock<ILogWriter>(MockBehavior.Strict);

             writer
            .Setup(s => s.Write(It.IsAny<LogItem>()));
             writer
            .Setup(s => s.GetTimeout())
            .Returns(timeout);
             qThread
            .Setup(s => s.SetTimeout(It.IsAny<int>()));

             LogCollector target = new LogCollector(qThread.Object, writer.Object);
             target.FilterAddID(1);
             qThread.Raise(s => s.OnReceive += null, message);

             writer
               .Verify(s => s.Write(It.IsAny<LogItem>()), Times.Never());

             target.FilterAddID(3);
             target.FilterAddID(1);
             qThread.Raise(s => s.OnReceive += null, message);

             writer
            .Verify(s => s.Write(It.Is<LogItem>(a => a.Equals(message))), Times.Once());
        }
示例#2
0
        static void InitBody()
        {
            if (options == null)
            {
                options = new Options("", "Log");
            }
            LogDefaultOptions.AddDefaultOptions(options);
            LogLevel.SetLevel(LogLevel.Always, options[LogDefaultOptions.AlwaysOption]);
            LogLevel.SetLevel(LogLevel.Fatal, options[LogDefaultOptions.FatalOption]);
            LogLevel.SetLevel(LogLevel.Error, options[LogDefaultOptions.ErrorOption]);
            LogLevel.SetLevel(LogLevel.Warning, options[LogDefaultOptions.WarningOption]);
            LogLevel.SetLevel(LogLevel.Info, options[LogDefaultOptions.InfoOption]);
            LogLevel.SetLevel(LogLevel.Event, options[LogDefaultOptions.EventOption]);
            LogLevel.SetLevel(LogLevel.Debug, options[LogDefaultOptions.DebugOption]);
            LogLevel.SetLevel(LogLevel.All, options[LogDefaultOptions.AllOption]);
            LogLevel.SetDefault(options["LogLevel"]);

            if (collector != null)
            {
                collector.ShutDown();
            }
            collector = new LogCollector(new ConcurrentQueued <LogItem>(new PoolThreadStarter()),
                                         new LogWriterFactory(options).GetWriter());

            if (container == null)
            {
                container = new LoggerContainer(category => new CheckingLogger(category, collector.Send, LogLevel.Default));
            }
            else
            {
                container.SetSender(collector.Send);
            }
            container.DefaultCategory = options.Get("LogDefaultCategory", "Default");
            init = true;
        }
示例#3
0
        public void ShutDownTest()
        {
            LogItem message = new LogItem(category, level, msg, ids, GetException());
             var qThread = new Mock<IQueued<LogItem>>(MockBehavior.Strict);
             var writer = new Mock<ILogWriter>(MockBehavior.Strict);

             qThread
            .Setup(s => s.Terminate());
             writer
            .Setup(s => s.GetTimeout())
            .Returns(timeout);
             qThread
            .Setup(s => s.SetTimeout(It.IsAny<int>()));

             LogCollector target = new LogCollector(qThread.Object, writer.Object);
             target.ShutDown();

             qThread
            .Verify(s => s.Terminate(), Times.Once());
        }
示例#4
0
        public void SendTest()
        {
            LogItem message = new LogItem(category, level, msg, ids, GetException());
             var qThread = new Mock<IQueued<LogItem>>(MockBehavior.Strict);
             var writer = new Mock<ILogWriter>(MockBehavior.Strict);

             qThread
            .Setup(s => s.Send(It.IsAny<LogItem>()));
             writer
            .Setup(s => s.GetTimeout())
            .Returns(timeout);
             qThread
            .Setup(s => s.SetTimeout(It.IsAny<int>()));

             LogCollector target = new LogCollector(qThread.Object, writer.Object);

             qThread
            .Verify(s => s.SetTimeout(It.Is<int>(a => a == timeout)));

             target.Send(message);

             qThread
            .Verify(s => s.Send(It.Is<LogItem>(i => i.Equals(message))), Times.Once());
        }
示例#5
0
        static void InitBody()
        {
            if (options == null)
            {
                options = new Options("", "Log");
            }
            LogDefaultOptions.AddDefaultOptions(options);
            LogLevel.SetLevel(LogLevel.Always, options[LogDefaultOptions.AlwaysOption]);
            LogLevel.SetLevel(LogLevel.Fatal,options[LogDefaultOptions.FatalOption]);
            LogLevel.SetLevel(LogLevel.Error,options[LogDefaultOptions.ErrorOption]);
            LogLevel.SetLevel(LogLevel.Warning,options[LogDefaultOptions.WarningOption]);
            LogLevel.SetLevel(LogLevel.Info,options[LogDefaultOptions.InfoOption]);
            LogLevel.SetLevel(LogLevel.Event,options[LogDefaultOptions.EventOption]);
            LogLevel.SetLevel(LogLevel.Debug,options[LogDefaultOptions.DebugOption]);
            LogLevel.SetLevel(LogLevel.All, options[LogDefaultOptions.AllOption]);
            LogLevel.SetDefault(options["LogLevel"]);

            if (collector != null)
            {
                collector.ShutDown();
            }
            collector = new LogCollector(new ConcurrentQueued<LogItem>(new PoolThreadStarter()),
                new LogWriterFactory(options).GetWriter());

            if (container == null)
            {
                container = new LoggerContainer(category => new CheckingLogger(category, collector.Send, LogLevel.Default));
            }
            else
            {
                container.SetSender(collector.Send);
            }
            container.DefaultCategory = options.Get("LogDefaultCategory", "Default");
            init = true;
        }