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(); } }
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); }); } }
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")); }
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")); }
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; }); } }