Example #1
0
        public void SanityParseJsonMessage()
        {
            var hierarchy      = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());
            var logzioAppender = new LogzioAppender();

            logzioAppender.AddToken("123456789");
            logzioAppender.AddListenerUrl(_dummy.DefaultUrl);
            logzioAppender.ParseJsonMessage(true);
            logzioAppender.ActivateOptions();
            hierarchy.Root.AddAppender(logzioAppender);
            hierarchy.Configured = true;
            var logger = LogManager.GetLogger(typeof(Log4netSanityTests));

            logger.Info("{ \"key1\" : \"val1\", \"key2\" : { \"key3\" : \"val3\"} }");
            LogManager.Shutdown();  // Flushes and closes
            JObject body = JObject.Parse(_dummy.Requests[0].Body);

            try
            {
                //Should append key-value pairs to log and parse them as Json
                body["key1"].ShouldBe("val1");
                body["key2"]["key3"].ShouldBe("val3");
            }
            catch (NullReferenceException e)
            {
                Assert.Fail("Failed to parse log as Json.");
            }
        }
Example #2
0
        private LogzioAppender SetupAppender(int bufferSize)
        {
            var hierarchy      = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());
            var logzioAppender = new LogzioAppender();

            logzioAppender.AddToken("123456789");
            logzioAppender.AddListenerUrl(_dummy.DefaultUrl);
            logzioAppender.AddBufferSize(bufferSize);
            logzioAppender.ActivateOptions();
            hierarchy.Root.AddAppender(logzioAppender);
            hierarchy.Configured = true;
            return(logzioAppender);
        }
        public void Sanity()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());
            var logzioAppender = new LogzioAppender();
            logzioAppender.AddToken("123456789");
            logzioAppender.AddListenerUrl(_dummy.DefaultUrl);
            logzioAppender.ActivateOptions();
            hierarchy.Root.AddAppender(logzioAppender);
            hierarchy.Configured = true;
            var logger = LogManager.GetLogger(typeof(Log4netSanityTests));

            logger.Info("Just a random log line");

            LogManager.Shutdown();  // Flushes and closes

            _dummy.Requests.Count.ShouldBe(1);
            _dummy.Requests[0].ShouldContain("Just a random log line");
        }
Example #4
0
        public void SanityParseInvalidJsonMessageAsString()
        {
            var hierarchy      = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());
            var logzioAppender = new LogzioAppender();

            logzioAppender.AddToken("123456789");
            logzioAppender.AddListenerUrl(_dummy.DefaultUrl);
            logzioAppender.ParseJsonMessage(true);
            logzioAppender.ActivateOptions();
            hierarchy.Root.AddAppender(logzioAppender);
            hierarchy.Configured = true;
            var logger = LogManager.GetLogger(typeof(Log4netSanityTests));

            logger.Info("{ Invalid json }");
            LogManager.Shutdown();  // Flushes and closes
            JObject body = JObject.Parse(_dummy.Requests[0].Body);

            //Should leave log as a string under 'message' field
            body["message"].ShouldBe("{ Invalid json }");
        }