Exemplo n.º 1
0
        public void MultiLineAppendFileLogTest()
        {
            var message1 = "[" + DateTime.Now.AddDays(-21) + "]" + "ERROR: This is testing logging multiple errors.";
            var message2 = "[" + DateTime.Now + "]" + "DEBUG: I am debugging information.";
            var logger = new FileLogger();

            var netlog_section = new NetLogSection();
            netlog_section.Logger.Name = "TestFileLogger";
            netlog_section.Logger.Type = "NetLog.Logger.FileLogger, NetLog.Logger";
            netlog_section.Logger.File.Name = "Test.log";
            netlog_section.Logger.File.Append = true;
            netlog_section.Logger.Layout.Type = "NetLog.Layout.Pattern, NetLog.Layout";
            netlog_section.Logger.Layout.Value = "[#date] #severity - #message";

            var counter = 0;

            logger.Log(netlog_section.Logger, "[ERROR]", message1);
            logger.Log(netlog_section.Logger, "[ERROR]", message2);

            using (StreamReader reader = new StreamReader(netlog_section.Logger.File.Name))
            {
                while (reader.ReadLine() != null) counter++;
            }

            Assert.IsTrue(counter > 0);
        }
Exemplo n.º 2
0
        public void BasicFileLoggerTest()
        {
            var message = "This is a Test";
            var severity = "ERROR";
            var expected = "[" + DateTime.Now.ToString("MM/dd/yyyy") +"]"
                + " " + severity + " - " + message;

            // build basic logger
            var logger = new FileLogger();
            var netlog_section = new NetLogSection();
            netlog_section.Logger.Name = "TestFileLogger";
            netlog_section.Logger.Type = "NetLog.Logger.FileLogger, NetLog.Logger";
            netlog_section.Logger.File.Name = "Test.log";
            netlog_section.Logger.File.Append = true;
            netlog_section.Logger.Layout.Type = "NetLog.Layout.Pattern, NetLog.Layout";
            netlog_section.Logger.Layout.Value = "[#date] #severity - #message";

            var output = logger.Log(netlog_section.Logger, severity, message);

            Assert.AreEqual(expected, output);
        }