Beispiel #1
0
        public void TraceOptionValues()
        {
            Assert.AreEqual(TraceOptions.None,
                            new TextWriterTraceListener(TextWriter.Null).TraceOutputOptions, "#1");
            Assert.AreEqual(TraceOptions.None,
                            new XmlWriterTraceListener(TextWriter.Null).TraceOutputOptions, "#2");

            StringWriter            sw = new StringWriter();
            TextWriterTraceListener t  = new TextWriterTraceListener(sw);

            Trace.CorrelationManager.StartLogicalOperation("foo");
            Trace.CorrelationManager.StartLogicalOperation("bar");
            t.TraceOutputOptions = TraceOptions.LogicalOperationStack | TraceOptions.DateTime | TraceOptions.Timestamp;            // | TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.Callstack;
            t.TraceEvent(null, null, TraceEventType.Error, 0, null);
            t.TraceEvent(null, "bulldog", TraceEventType.Error, 0);
            TraceEventCache cc   = new TraceEventCache();
            DateTime        date = cc.DateTime;
            long            time = cc.Timestamp;

            t.TraceData(cc, null, TraceEventType.Error, 0);
            t.TraceData(cc, null, TraceEventType.Error, 0);
            t.TraceTransfer(null, "bulldog", 0, "hoge", Guid.Empty);
            Trace.CorrelationManager.StopLogicalOperation();
            Trace.CorrelationManager.StopLogicalOperation();
            t.Close();
            string expected = String.Format(@" Error: 0 : 
bulldog Error: 0 : 
 Error: 0 : 
    LogicalOperationStack=bar, foo
    DateTime={0}
    Timestamp={1}" +

/*
 *  Callstack=   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
 * at System.Environment.get_StackTrace()
 * at System.Diagnostics.TraceEventCache.get_Callstack()
 * at System.Diagnostics.TraceListener.WriteFooter(TraceEventCache eventCache)
 * at System.Diagnostics.TraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object[] data)
 * at MonoTests.System.Diagnostics.TraceListenerTest.TraceOptionValues()
 * ...
 */
                                            @"
 Error: 0 : 
    LogicalOperationStack=bar, foo
    DateTime={0}
    Timestamp={1}
bulldog Transfer: 0 : hoge, relatedActivityId=00000000-0000-0000-0000-000000000000
", date.ToString("o"), time);  // date and time are in current culture

            Assert.AreEqual(expected, sw.ToString().Replace("\r\n", "\n"));
        }
Beispiel #2
0
        public void TraceEventAndTraceData()
        {
            StringWriter            sw = new StringWriter();
            TextWriterTraceListener t  = new TextWriterTraceListener(sw);

            t.TraceEvent(null, null, TraceEventType.Error, 0, null);
            t.TraceEvent(null, "bulldog", TraceEventType.Error, 0);
            TraceEventCache cc = new TraceEventCache();

            t.TraceData(cc, null, TraceEventType.Error, 0);
            t.TraceData(cc, null, TraceEventType.Error, 0);
            t.TraceTransfer(null, "bulldog", 0, "hoge", Guid.Empty);
            t.Close();
            string expected = @" Error: 0 : 
bulldog Error: 0 : 
 Error: 0 : 
 Error: 0 : 
bulldog Transfer: 0 : hoge, relatedActivityId=00000000-0000-0000-0000-000000000000
";

            Assert.AreEqual(expected, sw.ToString().Replace("\r\n", "\n"));
        }