File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -108,4 +108,6 @@ public abstract class Trace2Message
108
108
public int Line { get ; set ; }
109
109
110
110
public abstract string ToJson ( ) ;
111
+
112
+ public abstract string ToNormalString ( ) ;
111
113
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . IO ;
3
+
4
+ namespace GitCredentialManager ;
5
+
6
+ /// <summary>
7
+ /// The different format targets supported in the TRACE2 tracing
8
+ /// system.
9
+ /// </summary>
10
+ public enum Trace2FormatTarget
11
+ {
12
+ Event ,
13
+ Normal
14
+ }
15
+
16
+ public class Trace2StreamWriter : DisposableObject , ITrace2Writer
17
+ {
18
+ private readonly TextWriter _writer ;
19
+ private readonly Trace2FormatTarget _formatTarget ;
20
+
21
+ public bool Failed { get ; private set ; }
22
+
23
+ public Trace2StreamWriter ( TextWriter writer , Trace2FormatTarget formatTarget )
24
+ {
25
+ _writer = writer ;
26
+ _formatTarget = formatTarget ;
27
+ }
28
+
29
+ public void Write ( Trace2Message message )
30
+ {
31
+ try
32
+ {
33
+ _writer . Write ( Format ( message ) ) ;
34
+ _writer . Write ( '\n ' ) ;
35
+ _writer . Flush ( ) ;
36
+ }
37
+ catch
38
+ {
39
+ Failed = true ;
40
+ }
41
+ }
42
+
43
+ protected override void ReleaseManagedResources ( )
44
+ {
45
+ _writer . Dispose ( ) ;
46
+ base . ReleaseManagedResources ( ) ;
47
+ }
48
+
49
+ private string Format ( Trace2Message message )
50
+ {
51
+ EnsureArgument . NotNull ( message , nameof ( message ) ) ;
52
+
53
+ switch ( _formatTarget )
54
+ {
55
+ case Trace2FormatTarget . Event :
56
+ return message . ToJson ( ) ;
57
+ case Trace2FormatTarget . Normal :
58
+ return message . ToNormalString ( ) ;
59
+ default :
60
+ Console . WriteLine ( $ "warning: unrecognized format target '{ _formatTarget } ', disabling TRACE2 tracing.") ;
61
+ Failed = true ;
62
+ return "" ;
63
+ }
64
+ }
65
+ }
You can’t perform that action at this time.
0 commit comments