コード例 #1
0
ファイル: LoggerTest.cs プロジェクト: demosthenescode/netlog
        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);
        }
コード例 #2
0
ファイル: LoggerTest.cs プロジェクト: demosthenescode/netlog
        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);
        }
コード例 #3
0
ファイル: NetLog.cs プロジェクト: demosthenescode/netlog
 public NetLog(NetLogSection section)
 {
     _configuration = section;
     getLogger();
     assembly = Assembly.GetCallingAssembly().FullName;
 }
コード例 #4
0
ファイル: NetLog.cs プロジェクト: demosthenescode/netlog
 public NetLog()
 {
     _configuration = NetLogSection.Current;
     getLogger();
     assembly = Assembly.GetCallingAssembly().FullName;
 }
コード例 #5
0
ファイル: NetLogTests.cs プロジェクト: demosthenescode/netlog
 public void Init()
 {
     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";
 }