comparison Implab.Test/UnitTest1.cs @ 253:34df34841225 v3 v3.0.1-beta

Implab.Diagnostics drafts
author cin
date Mon, 12 Feb 2018 17:03:37 +0300
parents 6f4630d0bcd9
children c52691faaf21
comparison
equal deleted inserted replaced
252:6f4630d0bcd9 253:34df34841225
2 using System.Diagnostics; 2 using System.Diagnostics;
3 using System.Threading; 3 using System.Threading;
4 using Implab.Diagnostics; 4 using Implab.Diagnostics;
5 using Xunit; 5 using Xunit;
6 6
7 namespace Implab.Test 7 namespace Implab.Test {
8 { 8 using System.Threading.Tasks;
9 using static Trace<UnitTest1>; 9 using static Trace<UnitTest1>;
10 public class UnitTest1 10 public class UnitTest1 {
11 {
12 [Fact] 11 [Fact]
13 public void Test1() 12 public async Task Test1() {
14 { 13 var listener = new SimpleTraceListener(Console.Out);
15 var listener = new TextWriterTraceListener(Console.Out); 14
16 var source = TraceSource; 15 var source = TraceSource;
17 source.Switch.Level = SourceLevels.All; 16 source.Switch.Level = SourceLevels.All;
18 17
19 source.Listeners.Add(listener); 18 source.Listeners.Add(listener);
20 Trace.Listeners.Add(listener);
21 19
22 Trace.WriteLine("Hello!"); 20 using (var op = LogicalOperation(nameof(Test1)))
23 StartLogicalOperation(); 21 using (LogicalOperation("InnerOperation")){
24 22 await Task.Yield();
25 Trace.WriteLine("Inner"); 23 Log("Inner");
26 foreach(var x in Trace.CorrelationManager.LogicalOperationStack) 24 await Task.Yield();
27 Trace.WriteLine($"-{x}"); 25 Log("source event");
28 Log("source event"); 26 }
29
30 listener.IndentLevel = 1;
31
32 source.TraceData(TraceEventType.Start, 1, DateTime.Now);
33
34 StopLogicalOperation();
35 } 27 }
36 } 28 }
37 } 29 }