public void TestConsoleLoggingInvalidLevel()
        {
            Environment.SetEnvironmentVariable("hazelcast.logging.level", "asdf");
            var logger = new ConsoleLogFactory().GetLogger("logger");

            Assert.IsFalse(logger.IsFinestEnabled());
        }
        public void TestConsoleLoggingLevel()
        {
            Environment.SetEnvironmentVariable("hazelcast.logging.level", "info");
            var logger = new ConsoleLogFactory().GetLogger("logger");
            var original = Console.Out;
            try
            {
                var memoryStream = new MemoryStream();
                var streamWriter = new StreamWriter(memoryStream);
                Console.SetOut(streamWriter);
                var message1 = TestSupport.RandomString();
                var message2 = TestSupport.RandomString();
                logger.Info(message1);
                logger.Finest(message2);
                streamWriter.Flush();
                memoryStream.Seek(0, SeekOrigin.Begin);
                var log = new StreamReader(memoryStream).ReadToEnd();

                Assert.IsFalse(logger.IsFinestEnabled());
                Assert.That(logger.GetLevel(), Is.EqualTo(LogLevel.Info));
                Assert.That(log, Is.StringContaining(message1));
                Assert.That(log, Is.Not.StringContaining(message2));
            }
            finally
            {
                Console.SetOut(original);
                Environment.SetEnvironmentVariable("hazelcast.logging.level", null);
            }
        }
Ejemplo n.º 3
0
        public static ILoggerFactory NewLoggerFactory(string loggerType)
        {
            ILoggerFactory _loggerFactory = null;
            if ("console".Equals(loggerType))
            {
                _loggerFactory = new ConsoleLogFactory();
            }

            if (_loggerFactory == null)
            {
                _loggerFactory = (Debugger.IsAttached ? (ILoggerFactory)new TraceLogFactory() : new NoLogFactory());
                //_loggerFactory = new TraceLogFactory();
            }

            return _loggerFactory;
        }