Ejemplo n.º 1
0
        public void TestIgniteStartup()
        {
            var memoryLog = CreateMemoryLogger();
            var logger = new IgniteLog4NetLogger();

            var cfg = new IgniteConfiguration
            {
                DiscoverySpi = TestUtil.GetLocalDiscoverySpi(),
                Logger = logger
            };

            Func<IEnumerable<string>> getLogs = () => memoryLog.GetEvents().Select(x => x.MessageObject.ToString());

            using (var ignite = Ignition.Start(cfg))
            {
                Assert.IsTrue(getLogs().Contains(
                    string.Format("Starting Ignite.NET {0}", typeof(Ignition).Assembly.GetName().Version)));

                Assert.IsTrue(getLogs().Any(x => x.Contains(">>> Topology snapshot.")));

                Assert.IsInstanceOf<IgniteLog4NetLogger>(ignite.Logger);

                ignite.Logger.Info("Log from user code.");

                Assert.IsTrue(getLogs().Contains("Log from user code."));
            }

            Assert.IsTrue(getLogs().Contains("Grid is stopping."));
        }
Ejemplo n.º 2
0
        public void TestLogging()
        {
            var memoryLog = CreateMemoryLogger();
            var logger = new IgniteLog4NetLogger();

            Func<LoggingEvent> getLastLog = () => memoryLog.PopAllEvents().Single();

            // All parameters.
            logger.Log(LogLevel.Trace, "msg{0}", new object[] { 1 }, CultureInfo.InvariantCulture, "category",
                "java-err", new Exception("myException"));

            var log = getLastLog();
            Assert.AreEqual("msg1", log.MessageObject.ToString());
            Assert.AreEqual("category", log.LoggerName);
            Assert.AreEqual("java-err", log.Properties["nativeErrorInfo"]);
            Assert.AreEqual("myException", log.ExceptionObject.Message);
            Assert.AreEqual(Level.Trace, log.Level);

            // No Java error.
            logger.Log(LogLevel.Info, "msg{0}", new object[] { 1 }, CultureInfo.InvariantCulture, "category",
                null, new Exception("myException"));

            log = getLastLog();
            Assert.AreEqual("msg1", log.MessageObject.ToString());
            Assert.AreEqual("category", log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual("myException", log.ExceptionObject.Message);
            Assert.AreEqual(Level.Info, log.Level);

            // No exception.
            logger.Log(LogLevel.Debug, "msg{0}", new object[] { 1 }, CultureInfo.InvariantCulture, "category",
                null, null);

            log = getLastLog();
            Assert.AreEqual("msg1", log.MessageObject.ToString());
            Assert.AreEqual("category", log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual(null, log.ExceptionObject);
            Assert.AreEqual(Level.Debug, log.Level);

            // No params.
            logger.Log(LogLevel.Warn, "msg{0}", null, CultureInfo.InvariantCulture, "category", null, null);

            log = getLastLog();
            Assert.AreEqual("msg{0}", log.MessageObject.ToString());
            Assert.AreEqual("category", log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual(null, log.ExceptionObject);
            Assert.AreEqual(Level.Warn, log.Level);

            // No formatter.
            logger.Log(LogLevel.Error, "msg{0}", null, null, "category", null, null);

            log = getLastLog();
            Assert.AreEqual("msg{0}", log.MessageObject.ToString());
            Assert.AreEqual("category", log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual(null, log.ExceptionObject);
            Assert.AreEqual(Level.Error, log.Level);

            // No category.
            logger.Log(LogLevel.Error, "msg{0}", null, null, null, null, null);

            log = getLastLog();
            Assert.AreEqual("msg{0}", log.MessageObject.ToString());
            Assert.AreEqual(null, log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual(null, log.ExceptionObject);
            Assert.AreEqual(Level.Error, log.Level);

            // No message.
            logger.Log(LogLevel.Error, null, null, null, null, null, null);

            log = getLastLog();
            Assert.AreEqual(null, log.MessageObject);
            Assert.AreEqual(null, log.LoggerName);
            Assert.AreEqual(null, log.Properties["nativeErrorInfo"]);
            Assert.AreEqual(null, log.ExceptionObject);
            Assert.AreEqual(Level.Error, log.Level);
        }