public void InstanciationVerifyCreationDirectory () { var path = AppDomain.CurrentDomain.BaseDirectory; if (Directory.GetDirectories (path).Count (p => Path.GetFileName (p) == DateTime.Now.ToString ("yyyy-MM-dd")) == 1) Directory.Delete (Path.Combine (path, DateTime.Now.ToString ("yyyy-MM-dd")), true); using (var logStorage = new XmlWriterTraceListener("Application 1", AppDomain.CurrentDomain.BaseDirectory)) { logStorage.WriteLineEx ("Test", "1"); logStorage.Flush (); var nbDirectoryWithCurrentDay = Directory.GetDirectories (logStorage.BaseRootPath).Count (p => Path.GetFileName (p) == DateTime.Now.ToString ("yyyy-MM-dd")); Assert.IsTrue (nbDirectoryWithCurrentDay == 1, "Nb Directory With Current Day Name : " + nbDirectoryWithCurrentDay); } }
public void StressTrace10ThreadAnd10000TraceWithDelayed () { var path = AppDomain.CurrentDomain.BaseDirectory; var pathDirectoryDaily = Path.Combine (path, DateTime.Now.ToString ("yyyy-MM-dd")); if (Directory.GetDirectories (path).Count (p => Path.GetFileName (p) == DateTime.Now.ToString ("yyyy-MM-dd")) == 1) Directory.Delete (pathDirectoryDaily, true); System.Diagnostics.Debug.WriteLine ("DirectoryCreated"); using (var logStorage = new XmlWriterTraceListener("Application 1", AppDomain.CurrentDomain.BaseDirectory, 2, true)) { AdvancedTrace.AddTraceListener (AdvancedTrace.ListenerType.All, logStorage); var tasks = new List<Task> (); System.Diagnostics.Debug.WriteLine ("Listener added"); var stopWatch = new System.Diagnostics.Stopwatch (); stopWatch.Start (); for (int i = 0; i < 10; i++) { int i1 = i; tasks.Add (Task.Factory.StartNew (() => { for (int j = 0; j < 10000; j++) { AdvancedTrace.TraceInformation ("MyInformation " + i1 + " " + j, "Info"); } })); } logStorage.Flush (); Task.WaitAll (tasks.ToArray ()); System.Diagnostics.Debug.WriteLine ("Tasks finished added"); stopWatch.Stop (); var ts = stopWatch.Elapsed; System.Diagnostics.Debug.WriteLine ("Time Execute Trace :" + String.Format ("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)); Thread.Sleep (31000); var xmlDoc = new XmlDocument (); xmlDoc.Load (Path.Combine (pathDirectoryDaily, "Working_session_1.xml")); } }
public void StressTrace1ThreadAnd100000TraceWithoutDelayed () { var path = AppDomain.CurrentDomain.BaseDirectory; var pathDirectoryDaily = Path.Combine (path, DateTime.Now.ToString ("yyyy-MM-dd")); using (var logStorage = new XmlWriterTraceListener("Application 1", AppDomain.CurrentDomain.BaseDirectory, 2, false)) { AdvancedTrace.AddTraceListener (AdvancedTrace.ListenerType.All, logStorage); var stopWatch = new System.Diagnostics.Stopwatch (); stopWatch.Start (); for (int j = 0; j < 100000; j++) { AdvancedTrace.TraceInformation ("MyInformation " + j, "Info"); } logStorage.Flush (); stopWatch.Stop (); var ts = stopWatch.Elapsed; System.Diagnostics.Debug.WriteLine ("Time Execute Trace :" + String.Format ("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)); AdvancedTrace.RemoveTraceListener (AdvancedTrace.ListenerType.All, logStorage); } var xmlDoc = new XmlDocument (); xmlDoc.Load (Path.Combine (pathDirectoryDaily, "Working_session_1.xml")); }