コード例 #1
0
        public void Test_LogException()
        {
            string  repoName = getLogRepo2Test();
            ILog123 log      = Log123Manager.GetLogger(repoName, "a");

            var e = new Exception("TeSt");

            log.Trace(e);

            var appender   = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[0];
            var appenderEx = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[1];

            Assert.AreEqual("TRACE - TeSt;System.Exception: TeSt", appender.GetString().TrimEnd());
            Assert.AreEqual("TRACE - TeSt: log4net.ext123.Log123_test.Test_LogException()!!System.Exception: TeSt", appenderEx.GetString().TrimEnd());
            appender.Reset();
            appenderEx.Reset();

            log.Error(e, "Message {0}");
            Assert.AreEqual("ERROR - Message {0};System.Exception: TeSt", appender.GetString().TrimEnd());
            Assert.AreEqual("ERROR - Message {0}: log4net.ext123.Log123_test.Test_LogException()!!System.Exception: TeSt", appenderEx.GetString().TrimEnd());
            appender.Reset();
            appenderEx.Reset();

            log.Error(e, "Message {0}", 1);
            Assert.AreEqual("ERROR - Message 1;System.Exception: TeSt", appender.GetString().TrimEnd());
            Assert.AreEqual("ERROR - Message 1: log4net.ext123.Log123_test.Test_LogException()!!System.Exception: TeSt", appenderEx.GetString().TrimEnd());
        }
コード例 #2
0
        public void Test_PatternLayoutExt123_Length()
        {
            string configTemplate = @"
			<log4net>
				<appender name='a' type='log4net.Tests.Appender.StringAppender'>
					<layout type='log4net.ext123.PatternLayoutExt123'><conversionPattern value='%short-level: %message;'/></layout>
				</appender>
				<appender name='a0' type='log4net.Tests.Appender.StringAppender'>
					<layout type='log4net.ext123.PatternLayoutExt123'><conversionPattern value='%short-level{0}: %message;'/></layout>
				</appender>
				<appender name='a1' type='log4net.Tests.Appender.StringAppender'>
					<layout type='log4net.ext123.PatternLayoutExt123'><conversionPattern value='%short-level{1}: %message;'/></layout>
				</appender>
				<appender name='a2' type='log4net.Tests.Appender.StringAppender'>
					<layout type='log4net.ext123.PatternLayoutExt123'><conversionPattern value='%short-level{2}: %message;'/></layout>
				</appender>
				<appender name='a6' type='log4net.Tests.Appender.StringAppender'>
					<layout type='log4net.ext123.PatternLayoutExt123'><conversionPattern value='%short-level{6}: %message;'/></layout>
				</appender>
				<root>
					<level value='ALL' />
					<appender-ref ref='a' />
					<appender-ref ref='a0' />
					<appender-ref ref='a1' />
					<appender-ref ref='a2' />
					<appender-ref ref='a6' />
				</root>
			</log4net>"            ;


            string  repoName = getLogRepo2Test(configTemplate);
            ILog123 log      = Log123Manager.GetLogger(repoName, "root");

            log.Trace("trace");
            log.Debug("Message");
            log.Info(55);
            log.Warn(1);
            log.Error(2);
            log.Fatal(3);

            var a  = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[0];
            var a0 = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[1];
            var a1 = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[2];
            var a2 = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[3];
            var a6 = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[4];

            Assert.AreEqual("T: trace;D: Message;I: 55;W: 1;E: 2;F: 3;", a.GetString());
            Assert.AreEqual(": trace;: Message;: 55;: 1;: 2;: 3;", a0.GetString());
            Assert.AreEqual("T: trace;D: Message;I: 55;W: 1;E: 2;F: 3;", a1.GetString());
            Assert.AreEqual("TR: trace;DE: Message;IN: 55;WA: 1;ER: 2;FA: 3;", a2.GetString());
            Assert.AreEqual("TRACE : trace;DEBUG : Message;INFO  : 55;WARN  : 1;ERROR : 2;FATAL : 3;", a6.GetString());
        }
コード例 #3
0
        public void Test_PatternLayoutExt123()
        {
            string  repoName = getLogRepo2Test();
            ILog123 log      = Log123Manager.GetLogger(repoName, "a");

            log.Trace("trace");
            log.Debug("Message");
            log.Info(55);
            log.Warn(1);
            log.Error(2);
            log.Fatal(3);

            var appender = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[0];

            Assert.AreEqual("T: trace;D: Message;I: 55;W: 1;E: 2;F: 3;", appender.GetString());
        }
コード例 #4
0
        public void Test_LogMessage()
        {
            string  repoName = getLogRepo2Test();
            ILog123 log      = Log123Manager.GetLogger(repoName, "a");

            log.Trace("trace");
            log.Debug("Message");
            log.Info(55);

            var appender = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[0];

            Assert.AreEqual("TRACE - trace;DEBUG - Message;INFO - 55;", appender.GetString());
            appender.Reset();

            log.Warn("warn");
            log.Error("Message");
            log.Fatal(50);

            Assert.AreEqual("WARN - warn;ERROR - Message;FATAL - 50;", appender.GetString());
        }
コード例 #5
0
        public void Test_LogFormat()
        {
            string  repoName = getLogRepo2Test();
            ILog123 log      = Log123Manager.GetLogger(repoName, "a");

            log.Trace("t {0}");
            log.Trace("t {0}", 1);
            log.Debug("d {0}", 2);
            log.Info("i {0}", 3);

            var appender = (StringAppender)LogManager.GetRepository(repoName).GetAppenders()[0];

            Assert.AreEqual("TRACE - t {0};TRACE - t 1;DEBUG - d 2;INFO - i 3;", appender.GetString());
            appender.Reset();

            log.Warn("w {0}", 4);
            log.Error("e {0}", 5);
            log.Fatal("f {0}", 6);

            Assert.AreEqual("WARN - w 4;ERROR - e 5;FATAL - f 6;", appender.GetString());
        }