249
|
1 using System;
|
251
|
2 using System.Diagnostics;
|
249
|
3 using System.Threading;
|
252
|
4 using Implab.Diagnostics;
|
256
|
5 using System.Linq;
|
249
|
6 using Xunit;
|
|
7
|
253
|
8 namespace Implab.Test {
|
|
9 using System.Threading.Tasks;
|
252
|
10 using static Trace<UnitTest1>;
|
253
|
11 public class UnitTest1 {
|
249
|
12 [Fact]
|
253
|
13 public async Task Test1() {
|
|
14 var listener = new SimpleTraceListener(Console.Out);
|
256
|
15 listener.TraceOutputOptions |= TraceOptions.ThreadId;
|
253
|
16
|
252
|
17 var source = TraceSource;
|
|
18 source.Switch.Level = SourceLevels.All;
|
251
|
19
|
|
20 source.Listeners.Add(listener);
|
|
21
|
256
|
22 using (LogicalOperation("Test1")){
|
253
|
23 await Task.Yield();
|
256
|
24 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
|
|
25 await AsyncDummy();
|
|
26 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
|
253
|
27 }
|
249
|
28 }
|
256
|
29
|
|
30 async Task AsyncDummy() {
|
|
31 using(LogicalOperation("OuterDummy"))
|
|
32 using(LogicalOperation("InnerDummy")) {
|
|
33 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
|
|
34 await Task.Delay(1);
|
|
35 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
|
|
36 }
|
|
37 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
|
|
38 }
|
249
|
39 }
|
|
40 }
|