public static void Run() { var svc = new LogService(null); var dest = new ConsoleDestination("konzol"); dest.Colored = true; var filter = new FloodFilter(dest) { Interval = TimeSpan.FromSeconds(3d) }; //filter.MinLevel = MessageType.Error; //filter.MaxLevel = MessageType.Info; svc.RegisterDestination(filter); svc.Start(); svc.Write(new Message{ Type = MessageType.Info, Text = "This is info", From = "Tukhis" }); System.Threading.Thread.Sleep(4000); svc.Write(new Message{ Type = MessageType.Warning, Text = "Warning text goes here", From = "Beitzhen" }); System.Threading.Thread.Sleep(3500); svc.Write(new Message{ Type = MessageType.Error, Text = "This is error line", From = "Moisha" }); for(var i=0; i<1000000; i++) svc.Write(new Message{ Type = MessageType.Info, Text = "Loop trakhen" + i.ToString(), From = "Loop" }); svc.WaitForCompleteStop(); }
public void CSVFileDestinationStartByConfig2() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var xml = @"<log> <destination type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' path='{1}' create-dir='true' name-time-format='' /> </log>".Args(TNAME, TEST_DIR); var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) { File.Delete(fname); } using (Scope.OnExit(() => File.Delete(fname))) { svc.Configure(XMLConfiguration.CreateFromXML(xml).Root); svc.Start(); svc.Start(); svc.Write(new Message { Text = "1 message" }); svc.Write(new Message { Text = "2 message" }); svc.Write(new Message { Text = "3 message" }); svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void CSVFileDestinationStartByLaConfig() { string TNAME = "UnitTest-" + MethodInfo.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; const string DATE = "20131012"; var laStr = @"log {{ destination {{ type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' filename='$(@~path)$(::now fmt=yyyyMMdd value={1})-$($name).csv.log' }} }}".Args(TNAME, DATE); var cnf = LaconicConfiguration.CreateFromString(laStr); cnf.EnvironmentVarResolver = new Vars() { { "path", TEST_DIR } }; string fname = Path.Combine(TEST_DIR, DATE + "-" + FNAME); IOMiscUtils.EnsureFileEventuallyDeleted(fname); var logService = new LSVC(null); using (Scope.OnExit(() => File.Delete(fname))) { logService.Configure(cnf.Root); logService.Start(); logService.Write(new Message() { Text = "Msg 1" }); logService.Write(new Message() { Text = "Msg 2" }); logService.Write(new Message() { Text = "Msg 3" }); logService.WaitForCompleteStop(); Assert.IsTrue(File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void CSVFileDestinationStartByConfig1() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; const string DATE = "20131012"; var xml = @"<log> <destination type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' filename='$(@~path)$(::now fmt=yyyyMMdd value={1})-$($name).csv.log' create-dir='true' /> </log>".Args(TNAME, DATE); var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, DATE + "-" + FNAME); if (File.Exists(fname)) { File.Delete(fname); } using (Scope.OnExit(() => File.Delete(fname))) { var cfg = XMLConfiguration.CreateFromXML(xml); cfg.EnvironmentVarResolver = new Vars { { "path", TEST_DIR } }; svc.Configure(cfg.Root); svc.Start(); svc.Write(new Message { Text = "1 message" }); svc.Write(new Message { Text = "2 message" }); svc.Write(new Message { Text = "3 message" }); svc.WaitForCompleteStop(); Assert.IsTrue(File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void FloodFilter() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) { File.Delete(fname); } try { svc.RegisterDestination( new FloodFilter(new CSVFileDestination(TNAME, TEST_DIR) { CreateDir = true }) { Interval = TimeSpan.FromSeconds(10), MaxCount = 1000, MaxTextLength = 1024 } ); svc.Start(); for (var i = 0; i < 100000; i++) { svc.Write(new Message { Text = i.ToString() + " message" }); } svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(1, File.ReadAllLines(fname).Length); Assert.IsTrue(new FileInfo(fname).Length < 1500); } finally { File.Delete(fname); } }
public void FloodFilter() { var TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; var FNAME = TNAME + ".csv.log"; var fname = Path.Combine(TEST_DIR, FNAME); IOMiscUtils.EnsureFileEventuallyDeleted(fname); var svc = new LSVC(); try { svc.RegisterDestination( new FloodFilter(new CSVFileDestination(TNAME) { Path = TEST_DIR, FileName = FNAME }) { IntervalSec = 10, MaxCount = 1000, MaxTextLength = 1024 } ); svc.Start(); for (var i = 0; i < 100000; i++) { svc.Write(new Message { Text = i.ToString() + " message" }); } svc.WaitForCompleteStop(); Aver.IsTrue(File.Exists(fname)); Aver.AreEqual(1, File.ReadAllLines(fname).Length); Aver.IsTrue(new FileInfo(fname).Length < 1500); } finally { File.Delete(fname); } }
public void CSVFileDestinationStartByCode() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) { File.Delete(fname); } using (Scope.OnExit(() => File.Delete(fname))) { svc.RegisterDestination( new CSVFileDestination(TNAME, TEST_DIR) { CreateDir = true }); svc.Start(); svc.Write(new Message { Text = "1 message" }); svc.Write(new Message { Text = "2 message" }); svc.Write(new Message { Text = "3 message" }); svc.Write(new Message { Text = "4 message" }); svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(4, File.ReadAllLines(fname).Length); } }
public void TestDestination_CreateByLaConfig() { string la = @" log {{ destination {{ type='NFX.Log.Destinations.SQLServerDestination, NFX' name='{0}' connect-string='{1}' table-name='{2}' }} }}".Args(DEST_NAME, CONN_STR, TBL_NFXLOG_CUSTOM); var cfg = LaconicConfiguration.CreateFromString(la); dropTable(TBL_NFXLOG_CUSTOM); var logService = new LSVC(null); using (Scope.OnExit(() => dropTable(TBL_NFXLOG_CUSTOM))) { logService.Configure(cfg.Root); logService.Start(); logService.Write(new Message() { Text = "Msg 1" }); logService.Write(new Message() { Text = "Msg 2" }); logService.Write(new Message() { Text = "Msg 3" }); logService.WaitForCompleteStop(); DataTable tbl = getLogTableRecords(TBL_NFXLOG_CUSTOM); Assert.AreEqual(3, tbl.Rows.Count); } }
public void TestDestination_Autocreation_CustomTableName() { dropTable(TBL_NFXLOG_CUSTOM); var logService = new LSVC(null); using (Scope.OnExit(() => dropTable(TBL_NFXLOG_CUSTOM))) { logService.RegisterDestination(new SQLServerDestination(DEST_NAME, CONN_STR, TBL_NFXLOG_CUSTOM)); logService.Start(); logService.Write(new Message() { Text = "Msg 1" }); logService.WaitForCompleteStop(); Assert.IsTrue(tableExists(TBL_NFXLOG_CUSTOM)); } }
public void CSVFileDestinationStartByCode() { var TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; var FNAME = TNAME + ".csv.log"; var fname = Path.Combine(TEST_DIR, FNAME); IOMiscUtils.EnsureFileEventuallyDeleted(fname); using (var svc = new LSVC()) using (Scope.OnExit(() => File.Delete(fname))) { svc.RegisterDestination( new CSVFileDestination(TNAME) { Path = TEST_DIR, FileName = FNAME }); svc.Start(); svc.Write(new Message { Text = "1 message" }); svc.Write(new Message { Text = "2 message" }); svc.Write(new Message { Text = "3 message" }); svc.Write(new Message { Text = "4 message" }); svc.WaitForCompleteStop(); Aver.IsTrue(File.Exists(fname)); Aver.AreEqual(4, File.ReadAllLines(fname).Length); } }
public void TestDestination_Write() { createTable(TBL_NFXLOG); var logService = new LSVC(null); using (Scope.OnExit(() => dropTable(TBL_NFXLOG))) { logService.RegisterDestination(new SQLServerDestination(DEST_NAME, CONN_STR)); logService.Start(); for (int i = 0; i < 3; i++) { logService.Write(new Message() { Text = "Msg " + i }); } logService.WaitForCompleteStop(); Assert.AreEqual(3, getLogTableRecords(TBL_NFXLOG).Rows.Count); } }
public void CSVFileDestinationStartByConfig2() { var TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; var FNAME = TNAME + ".csv.log"; var xml = @"<log> <destination type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' path='{1}' file-name='$($name).csv.log' /> </log>".Args(TNAME, TEST_DIR); var fname = Path.Combine(TEST_DIR, FNAME); IOMiscUtils.EnsureFileEventuallyDeleted(fname); using (var svc = new LSVC()) using (Scope.OnExit(() => File.Delete(fname))) { svc.Configure(XMLConfiguration.CreateFromXML(xml).Root); svc.Start(); svc.Write(new Message { Text = "1 message" }); svc.Write(new Message { Text = "2 message" }); svc.Write(new Message { Text = "3 message" }); svc.WaitForCompleteStop(); Aver.IsTrue(File.Exists(fname)); Aver.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void CSVFileDestinationStartByCode() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) File.Delete(fname); using (Scope.OnExit(() => File.Delete(fname))) { svc.RegisterDestination( new CSVFileDestination(TNAME, TEST_DIR){ CreateDir = true }); svc.Start(); svc.Write(new Message{Text = "1 message"}); svc.Write(new Message{Text = "2 message"}); svc.Write(new Message{Text = "3 message"}); svc.Write(new Message{Text = "4 message"}); svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(4, File.ReadAllLines(fname).Length); } }
public void TestDestination_Write() { createTable(TBL_NFXLOG); var logService = new LSVC(null); using (Scope.OnExit(() => dropTable(TBL_NFXLOG))) { logService.RegisterDestination(new SQLServerDestination(DEST_NAME, CONN_STR)); logService.Start(); for (int i = 0; i < 3; i++) logService.Write(new Message() { Text = "Msg " + i }); logService.WaitForCompleteStop(); Assert.AreEqual(3, getLogTableRecords(TBL_NFXLOG).Rows.Count); } }
public void FloodFilter() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) File.Delete(fname); try { svc.RegisterDestination( new FloodFilter(new CSVFileDestination(TNAME, TEST_DIR){ CreateDir = true }) { Interval = TimeSpan.FromSeconds(10), MaxCount = 1000, MaxTextLength = 1024 } ); svc.Start(); for (var i=0; i < 100000; i++) svc.Write(new Message{Text = i.ToString() +" message"}); svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(1, File.ReadAllLines(fname).Length); Assert.IsTrue( new FileInfo(fname).Length < 1500); } finally { File.Delete(fname); } }
public void CSVFileDestinationStartByLaConfig() { string TNAME = "UnitTest-" + MethodInfo.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; const string DATE = "20131012"; var laStr = @"log {{ destination {{ type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' filename='$(@~path)$(::now fmt=yyyyMMdd value={1})-$($name).csv.log' }} }}".Args(TNAME, DATE); var cnf = LaconicConfiguration.CreateFromString(laStr); cnf.EnvironmentVarResolver = new Vars() { { "path", TEST_DIR}}; string fname = Path.Combine(TEST_DIR, DATE + "-" + FNAME); IOMiscUtils.EnsureFileEventuallyDeleted(fname); var logService = new LSVC(null); using (Scope.OnExit(() => File.Delete(fname))) { logService.Configure(cnf.Root); logService.Start(); logService.Write(new Message() { Text = "Msg 1"}); logService.Write(new Message() { Text = "Msg 2" }); logService.Write(new Message() { Text = "Msg 3" }); logService.WaitForCompleteStop(); Assert.IsTrue(File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void CSVFileDestinationStartByConfig2() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; var xml= @"<log> <destination type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' path='{1}' create-dir='true' name-time-format='' /> </log>".Args(TNAME, TEST_DIR); var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, FNAME); if (File.Exists(fname)) File.Delete(fname); using (Scope.OnExit(() => File.Delete(fname))) { svc.Configure(XMLConfiguration.CreateFromXML(xml).Root); svc.Start(); svc.Start(); svc.Write(new Message{Text = "1 message"}); svc.Write(new Message{Text = "2 message"}); svc.Write(new Message{Text = "3 message"}); svc.WaitForCompleteStop(); Assert.AreEqual(true, File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }
public void CSVFileDestinationStartByConfig1() { string TNAME = "UnitTest-" + MethodBase.GetCurrentMethod().Name; string FNAME = TNAME + ".csv.log"; const string DATE = "20131012"; var xml= @"<log> <destination type='NFX.Log.Destinations.CSVFileDestination, NFX' name='{0}' filename='$(@~path)$(::now fmt=yyyyMMdd value={1})-$($name).csv.log' create-dir='true' /> </log>".Args(TNAME, DATE); var svc = new LSVC(null); var fname = Path.Combine(TEST_DIR, DATE + "-" + FNAME); if (File.Exists(fname)) File.Delete(fname); using (Scope.OnExit(() => File.Delete(fname))) { var cfg = XMLConfiguration.CreateFromXML(xml); cfg.EnvironmentVarResolver = new Vars { { "path", TEST_DIR } }; svc.Configure(cfg.Root); svc.Start(); svc.Write(new Message{Text = "1 message"}); svc.Write(new Message{Text = "2 message"}); svc.Write(new Message{Text = "3 message"}); svc.WaitForCompleteStop(); Assert.IsTrue(File.Exists(fname)); Assert.AreEqual(3, File.ReadAllLines(fname).Length); } }