public void when_tracing_activity_then_builds_trace_log() { if (File.Exists(LogFile)) File.Delete(LogFile); var xml = new XmlWriterTraceListener(LogFile, "Xml"); manager.AddListener("*", xml); manager.SetTracingLevel("*", SourceLevels.All); var tracer = Tracer.Get("Foo"); using (tracer.StartActivity("Outer")) { tracer.Info("Hello info from outer"); using (tracer.StartActivity("Inner")) { tracer.Warn("Warn from inner"); Tracer.Get("Foo.Bar").Error("Something failed on another class!"); } } xml.Flush(); System.Threading.Thread.Sleep(1000); xml.Close(); Process.Start(SvcViewer, new FileInfo(LogFile).FullName); }
public void TraceEvent1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.TraceEvent (null, null, TraceEventType.Error, 4, null); x.Close (); Assert.AreEqual (sample2.Replace ('\'', '"'), sw.ToString ()); }
public void WriteLine1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.WriteLine ("sample"); x.Close (); Assert.AreEqual (sample1.Replace ('\'', '"'), sw.ToString ()); }
static void Main(string[] args) { WriteLine("Option 1"); System.Diagnostics.TraceSource trace = new TraceSource("./1_Trace.log"); trace.TraceEvent(TraceEventType.Error, 123, "Option A: System.Diagnostics.TraceSource trace"); WriteLine("Option 2: writes a file as 'TraceEventType.Error' and source 'Option B...'"); using (System.Diagnostics.XmlWriterTraceListener log1 = new XmlWriterTraceListener("./2_Error.log")) { log1.TraceEvent(new TraceEventCache(), "Option B: System.Diagnostics.XmlWriterTraceListener", TraceEventType.Error, 123); log1.Flush(); } WriteLine("Option 3"); WriteLine("Throws: An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll"); //System.Diagnostics.EventInstance errorEvent = new EventInstance(123, 1, EventLogEntryType.Error); //EventLog.WriteEvent("MyAppErrors", errorEvent, "the message"); WriteLine("Option 4: writes to the EventLog"); EventLog logEntry = new EventLog(); logEntry.Source = "Application"; logEntry.WriteEntry("the message", EventLogEntryType.Error); WriteLine("Option 5: writes a file as 'TraceEventType.Information' and source 'Trace'"); System.Diagnostics.XmlWriterTraceListener listener = new XmlWriterTraceListener("./5_Errror.log"); listener.WriteLine("the log message"); listener.Flush(); listener.Close(); // See Output window: // Error.log: a trace message WriteLine("Option 6: Trace.WriteLine with 'Error.log' as category"); Trace.WriteLine("a trace message", "Error.log"); WriteLine("Done"); ReadLine(); }
public void TraceDataWithCache1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); TraceEventCache cc = new TraceEventCache (); x.TraceData (cc, null, TraceEventType.Error, 2); x.TraceData (cc, null, TraceEventType.Error, 3); x.Close (); Assert.AreEqual (sample4.Replace ('\'', '"'), sw.ToString ()); }
public void Fail1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); TraceEventCache cc = new TraceEventCache (); x.Fail ("error summary", "error details"); x.Close (); Assert.AreEqual (sample7.Replace ('\'', '"'), sw.ToString ()); }
public void TraceTransfer1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.TraceTransfer (null, "bulldog", 0, "hoge", Guid.Empty); x.Close (); Assert.AreEqual (sample6.Replace ('\'', '"'), sw.ToString ()); }