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