Ejemplo n.º 1
0
        public void FileDestinationFilenameConfigTest()
        {
            DateTime now = App.LocalizedTime;

            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, "{0:yyyyMMdd}-{1}.log".Args(now, TNAME));

            File.Delete(FNAME);

            var xml = @"<log>
                            <destination type='NFX.Log.Destinations.DebugDestination, NFX' name='{0}' path='{1}'/>
                       </log>".Args(TNAME, TEST_DIR);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(FNAME)))
                {
                    svc.Configure(XMLConfiguration.CreateFromXML(xml).Root);
                    svc.Start();

                    Assert.IsTrue(File.Exists(FNAME));

                    svc.WaitForCompleteStop();
                }
        }
Ejemplo n.º 2
0
        public void FileDestinationFilenameConfigTest()
        {
            DateTime now = App.LocalizedTime;

            var TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            var FNAME = "{0:yyyyMMdd}-{1}.log".Args(now, TNAME);

            var fname = Path.Combine(TEST_DIR, FNAME);

            IOMiscUtils.EnsureFileEventuallyDeleted(fname);

            var xml = @"<log>
                     <destination type='NFX.Log.Destinations.DebugDestination, NFX'
                                  name='{0}'
                                  path='{1}'
                                  filename='{2}'/>
                   </log>".Args(TNAME, TEST_DIR, FNAME);

            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(fname)))
                {
                    svc.Configure(XMLConfiguration.CreateFromXML(xml).Root);
                    svc.Start();

                    Aver.IsTrue(File.Exists(fname));

                    svc.WaitForCompleteStop();
                }
        }
Ejemplo n.º 3
0
        public void CSVDestinationFilenameConfigTest()
        {
            DateTime now = App.LocalizedTime;

            string TNAME = "TestDest" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, "{0}-{1:yyyyMMdd}{2}".Args(TNAME, now, CSVFileDestination.DEFAULT_EXTENSION));

            File.Delete(FNAME);

            var xml= @"<log>
                            <destination type='NFX.Log.Destinations.CSVFileDestination, NFX'
                             name='{0}' path='{1}' create-dir='true' name-time-format='yyyyMMdd'/>
                       </log>".Args(TNAME, TEST_DIR);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
            using (Scope.OnExit(() => File.Delete(FNAME)))
            {
                svc.Configure(XMLConfiguration.CreateFromXML(xml).Root);
                svc.Start();

                Assert.IsTrue(File.Exists(FNAME));

                svc.WaitForCompleteStop();
            }
        }
Ejemplo n.º 4
0
        public void DebugDestinationWriteTest()
        {
            var TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            var FNAME = TNAME + ".log";

            var fname = Path.Combine(TEST_DIR, FNAME);

            IOMiscUtils.EnsureFileEventuallyDeleted(FNAME);

            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(fname)))
                {
                    svc.RegisterDestination(
                        new DebugDestination(TNAME)
                    {
                        FileName = FNAME, Path = TEST_DIR
                    });
                    svc.Start();

                    DateTime now = new DateTime(2013, 1, 2, 3, 4, 5);

                    for (var i = 0; i < 10; i++)
                    {
                        svc.Write(new Message {
                            Text = i.ToString(), TimeStamp = now
                        });
                    }

                    svc.WaitForCompleteStop();

                    Aver.IsTrue(File.Exists(fname));
                    string[] lines = File.ReadAllLines(fname);

                    Aver.AreEqual(10, lines.Length);
                    lines.Select((s, i) =>
                    {
                        Aver.AreEqual(
                            "20130102-030405.000000|   {0}||Debug|{1}||0|".Args(Thread.CurrentThread.ManagedThreadId, i),
                            s);
                        return(0);
                    }).ToArray();
                }
        }
Ejemplo n.º 5
0
        public void DebugDestinationFilenameDefaultTest()
        {
            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, TNAME + ".log");

            File.Delete(FNAME);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(FNAME)))
                {
                    svc.RegisterDestination(new DebugDestination(TNAME, FNAME));
                    svc.Start();

                    Assert.IsTrue(File.Exists(FNAME));

                    svc.WaitForCompleteStop();
                }
        }
Ejemplo n.º 6
0
        public void DebugDestinationFilenameDefaultTest()
        {
            var TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            var FNAME = Path.Combine(TEST_DIR, TNAME + ".log");

            IOMiscUtils.EnsureFileEventuallyDeleted(FNAME);

            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(FNAME)))
                {
                    svc.RegisterDestination(new DebugDestination(TNAME)
                    {
                        FileName = FNAME
                    });
                    svc.Start();

                    Aver.IsTrue(File.Exists(FNAME));

                    svc.WaitForCompleteStop();
                }
        }
Ejemplo n.º 7
0
        public void DebugDestinationWriteTest()
        {
            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, TNAME + ".log");

            File.Delete(FNAME);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(FNAME)))
                {
                    svc.RegisterDestination(new DebugDestination(TNAME, TNAME + ".log", TEST_DIR));
                    svc.Start();

                    DateTime now = new DateTime(2013, 1, 2, 3, 4, 5);

                    for (var i = 0; i < 10; i++)
                    {
                        svc.Write(new Message {
                            Text = i.ToString(), TimeStamp = now
                        });
                    }

                    svc.WaitForCompleteStop();

                    string[] lines = File.ReadAllLines(FNAME);

                    Assert.AreEqual(10, lines.Length);
                    lines.Select((s, i) =>
                    {
                        Assert.AreEqual(
                            "20130102-030405.000000|   {0}||Debug|{1}||0|".Args(Thread.CurrentThread.ManagedThreadId, i),
                            s);
                        return(0);
                    });
                }
        }
Ejemplo n.º 8
0
        public void CSVDestinationDefaultFilenameTest()
        {
            var FNAME = "{0:yyyyMMdd}.log.csv".Args(App.LocalizedTime);

            var fname = Path.Combine(TEST_DIR, FNAME);

            IOMiscUtils.EnsureFileEventuallyDeleted(fname);

            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(fname)))
                {
                    svc.RegisterDestination(
                        new CSVFileDestination()
                    {
                        Path = TEST_DIR
                    });
                    svc.Start();

                    Aver.IsTrue(File.Exists(fname));

                    svc.WaitForCompleteStop();
                }
        }
Ejemplo n.º 9
0
        public void LogLevelsTest()
        {
            DateTime now  = App.LocalizedTime;
            DateTime time = new DateTime(now.Year, now.Month, now.Day, 3, 4, 5);

            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, "{0:yyyyMMdd}-{1}.log".Args(now, TNAME));

            File.Delete(FNAME);

            var xml = @"<log>
                            <destination type='NFX.Log.Destinations.DebugDestination, NFX'
                                name='{0}' path='{1}'
                                levels='DebugB-DebugC,InfoB-InfoD,Warning,Emergency'/>
                       </log>".Args(TNAME, TEST_DIR);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
                using (Scope.OnExit(() => File.Delete(FNAME)))
                {
                    svc.Configure(XMLConfiguration.CreateFromXML(xml).Root);
                    svc.Start();

                    Assert.IsTrue(File.Exists(FNAME));

                    Array mts = Enum.GetValues(typeof(MessageType));

                    foreach (var mt in mts)
                    {
                        svc.Write(new Message {
                            Type = (MessageType)mt, Text = ((int)mt).ToString(), TimeStamp = now
                        });
                    }

                    svc.WaitForCompleteStop();

                    string[] lines = File.ReadAllLines(FNAME);

                    Assert.AreEqual(7, lines.Length);

                    lines.Select((s, i) =>
                    {
                        var sa = s.Split('|');
                        MessageType mt;

                        Assert.IsTrue(Enum.TryParse(sa[3], out mt));
                        Assert.AreEqual(
                            "{0:yyyyMMdd}-030405.000000|   {1}||Debug|{2}||0|".Args(now, Thread.CurrentThread.ManagedThreadId, (int)mt),
                            s);
                        return(0);
                    });
                }

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.DebugA, MessageType.DebugZ)
            },
                Destination.ParseLevels("DebugA-DebugZ"));

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.Debug, MessageType.Info)
            },
                Destination.ParseLevels("-Info"));

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.Info, MessageType.CatastrophicError)
            },
                Destination.ParseLevels("Info-"));

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.Trace, MessageType.TraceZ),
                new Tuple <MessageType, MessageType>(MessageType.Info, MessageType.CatastrophicError)
            },
                Destination.ParseLevels("Trace - TraceZ, Info-"));

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.Trace, MessageType.Trace),
                new Tuple <MessageType, MessageType>(MessageType.Info, MessageType.Info),
                new Tuple <MessageType, MessageType>(MessageType.Warning, MessageType.Warning)
            },
                Destination.ParseLevels("Trace | Info | Warning"));

            Assert.AreEqual(
                new Destination.LevelsList {
                new Tuple <MessageType, MessageType>(MessageType.Trace, MessageType.Trace),
                new Tuple <MessageType, MessageType>(MessageType.Info, MessageType.Info)
            },
                Destination.ParseLevels("Trace; Info"));
        }
Ejemplo n.º 10
0
        public void CSVDestinationFilenameDefaultTest()
        {
            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, TNAME + CSVFileDestination.DEFAULT_EXTENSION);

            File.Delete(FNAME);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
            using (Scope.OnExit(() => File.Delete(FNAME)))
            {
                svc.RegisterDestination(new CSVFileDestination(TNAME, TEST_DIR));
                svc.Start();

                Assert.IsTrue(File.Exists(FNAME));

                svc.WaitForCompleteStop();
            }
        }
Ejemplo n.º 11
0
        public void LogLevelsTest()
        {
            DateTime now  = App.LocalizedTime;
            DateTime time = new DateTime(now.Year, now.Month, now.Day, 3,4,5);

            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, "{0:yyyyMMdd}-{1}.log".Args(now, TNAME));

            File.Delete(FNAME);

            var xml= @"<log>
                            <destination type='NFX.Log.Destinations.DebugDestination, NFX'
                                name='{0}' path='{1}'
                                levels='DebugB-DebugC,InfoB-InfoD,Warning,Emergency'/>
                       </log>".Args(TNAME, TEST_DIR);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
            using (Scope.OnExit(() => File.Delete(FNAME)))
            {
                svc.Configure(XMLConfiguration.CreateFromXML(xml).Root);
                svc.Start();

                Assert.IsTrue(File.Exists(FNAME));

                Array mts = Enum.GetValues(typeof(MessageType));

                foreach (var mt in mts)
                    svc.Write(new Message { Type = (MessageType)mt, Text = ((int)mt).ToString(), TimeStamp = now });

                svc.WaitForCompleteStop();

                string[] lines = File.ReadAllLines(FNAME);

                Assert.AreEqual(7, lines.Length);

                lines.Select((s,i) =>
                {
                    var sa = s.Split('|');
                    MessageType mt;

                    Assert.IsTrue(Enum.TryParse(sa[3], out mt));
                    Assert.AreEqual(
                        "{0:yyyyMMdd}-030405.000000|   {1}||Debug|{2}||0|".Args(now, Thread.CurrentThread.ManagedThreadId, (int)mt),
                        s);
                    return 0;
                });
            }

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.DebugA, MessageType.DebugZ) },
                Destination.ParseLevels("DebugA-DebugZ"));

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.Debug, MessageType.Info) },
                Destination.ParseLevels("-Info"));

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.Info, MessageType.CatastrophicError) },
                Destination.ParseLevels("Info-"));

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.Trace, MessageType.TraceZ),
                                             new Tuple<MessageType, MessageType>(MessageType.Info, MessageType.CatastrophicError) },
                Destination.ParseLevels("Trace - TraceZ, Info-"));

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.Trace, MessageType.Trace),
                                             new Tuple<MessageType, MessageType>(MessageType.Info, MessageType.Info),
                                             new Tuple<MessageType, MessageType>(MessageType.Warning, MessageType.Warning) },
                Destination.ParseLevels("Trace | Info | Warning"));

            Assert.AreEqual(
                new Destination.LevelsList { new Tuple<MessageType, MessageType>(MessageType.Trace, MessageType.Trace),
                                             new Tuple<MessageType, MessageType>(MessageType.Info, MessageType.Info) },
                Destination.ParseLevels("Trace; Info"));
        }
Ejemplo n.º 12
0
        public void DebugDestinationWriteTest()
        {
            string TNAME = "TestDest-" + MethodBase.GetCurrentMethod().Name;
            string FNAME = Path.Combine(TEST_DIR, TNAME + ".log");

            File.Delete(FNAME);

            //var log = new TestMemoryLog();
            //using (var app = new TestApplication { Log = log })
            using (var svc = new TSLS())
            using (Scope.OnExit(() => File.Delete(FNAME)))
            {
                svc.RegisterDestination(new DebugDestination(TNAME, TNAME + ".log", TEST_DIR));
                svc.Start();

                DateTime now = new DateTime(2013, 1, 2, 3, 4, 5);

                for (var i=0; i < 10; i++)
                    svc.Write(new Message { Text = i.ToString(), TimeStamp = now });

                svc.WaitForCompleteStop();

                string[] lines = File.ReadAllLines(FNAME);

                Assert.AreEqual(10, lines.Length);
                lines.Select((s, i) =>
                {
                    Assert.AreEqual(
                        "20130102-030405.000000|   {0}||Debug|{1}||0|".Args(Thread.CurrentThread.ManagedThreadId, i),
                        s);
                    return 0;
                });
            }
        }