File tree Expand file tree Collapse file tree
src/coverlet.console/Logging Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,13 +16,15 @@ class ConsoleLogger : ILogger
1616 public LogLevel Level { get ; set ; } = LogLevel . Normal ;
1717
1818 /// <summary>
19- /// Enables writing all trace-level diagnostics to the specified file, regardless of the
20- /// configured console <see cref="Level"/>. Intended for CI troubleshooting (e.g. --diag).
19+ /// Enables writing diagnostics to the specified file. All log messages (including trace-level
20+ /// messages that may be suppressed from the console by <see cref="Level"/>) are written to the file.
21+ /// Intended for CI troubleshooting (e.g. --diag).
2122 /// </summary>
2223 public void EnableDiagnosticFile ( string path )
2324 {
2425 ArgumentNullException . ThrowIfNull ( path ) ;
2526
27+ StreamWriter newWriter = null ;
2628 try
2729 {
2830 string directory = Path . GetDirectoryName ( Path . GetFullPath ( path ) ) ;
@@ -31,11 +33,22 @@ public void EnableDiagnosticFile(string path)
3133 Directory . CreateDirectory ( directory ) ;
3234 }
3335
34- _diagWriter = new StreamWriter ( path , append : false ) { AutoFlush = true } ;
36+ newWriter = new StreamWriter ( path , append : false ) { AutoFlush = true } ;
37+
38+ lock ( s_sync )
39+ {
40+ _diagWriter ? . Dispose ( ) ;
41+ _diagWriter = newWriter ;
42+ }
3543 }
3644 catch ( Exception ex )
3745 {
38- _diagWriter = null ;
46+ newWriter ? . Dispose ( ) ;
47+ lock ( s_sync )
48+ {
49+ _diagWriter = null ;
50+ }
51+
3952 LogWarning ( $ "Unable to create diagnostic file '{ path } ': { ex . Message } ") ;
4053 }
4154 }
You can’t perform that action at this time.
0 commit comments