Skip to content

Commit f64d3e9

Browse files
authored
Merge pull request #94 from mjcheetham/debug-trace
Add debug trace listener when debugger is attached
2 parents 8ef6914 + 7a003ac commit f64d3e9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/shared/Microsoft.Git.CredentialManager/ApplicationBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public Task<int> RunAsync(string[] args)
3636
Debugger.Break();
3737
}
3838

39+
// Add the debug tracer if the debugger is attached
40+
if (Debugger.IsAttached)
41+
{
42+
Context.Trace.AddListener(new DebugTraceWriter());
43+
}
44+
3945
// Enable tracing
4046
if (Context.Settings.GetTracingEnabled(out string traceValue))
4147
{

src/shared/Microsoft.Git.CredentialManager/Trace.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the MIT license.
33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
8+
using System.Text;
79

810
namespace Microsoft.Git.CredentialManager
911
{
@@ -331,4 +333,15 @@ private static string FormatText(string message, string filePath, int lineNumber
331333
return text;
332334
}
333335
}
336+
337+
public class DebugTraceWriter : TextWriter
338+
{
339+
public override Encoding Encoding => Encoding.UTF8;
340+
341+
public override void Write(char value) => Debug.Write(value);
342+
343+
public override void Write(string value) => Debug.Write(value);
344+
345+
public override void WriteLine(string value) => Debug.WriteLine(value);
346+
}
334347
}

0 commit comments

Comments
 (0)