@@ -43,41 +43,31 @@ internal ProcessExecution(Process process, ILogger logger, ProcessInvocationOpti
4343 /// <inheritdoc />
4444 public bool Start ( )
4545 {
46- var suppressLogging = _options . SuppressLogging ;
47-
4846 var started = _process . Start ( ) ;
4947
5048 if ( ! started )
5149 {
52- if ( ! suppressLogging )
53- {
54- _logger . LogDebug ( "Failed to start process {FileName} with args: {Args}" , FileName , string . Join ( " " , Arguments ) ) ;
55- }
50+ _logger . LogDebug ( "Failed to start process {FileName} with args: {Args}" , FileName , string . Join ( " " , Arguments ) ) ;
5651 return false ;
5752 }
5853
59- if ( ! suppressLogging )
60- {
61- _logger . LogDebug ( "Started {FileName} with PID: {ProcessId}" , FileName , _process . Id ) ;
62- }
54+ _logger . LogDebug ( "Started {FileName} in {WorkingDirectory} with PID: {ProcessId}" , FileName , _process . StartInfo . WorkingDirectory , _process . Id ) ;
6355
6456 // Start stream forwarders
6557 _stdoutForwarder = Task . Run ( async ( ) =>
6658 {
6759 await ForwardStreamToLoggerAsync (
6860 _process . StandardOutput ,
6961 "stdout" ,
70- _options . StandardOutputCallback ,
71- suppressLogging ) ;
62+ _options . StandardOutputCallback ) ;
7263 } ) ;
7364
7465 _stderrForwarder = Task . Run ( async ( ) =>
7566 {
7667 await ForwardStreamToLoggerAsync (
7768 _process . StandardError ,
7869 "stderr" ,
79- _options . StandardErrorCallback ,
80- suppressLogging ) ;
70+ _options . StandardErrorCallback ) ;
8171 } ) ;
8272
8373 return true ;
@@ -86,29 +76,18 @@ await ForwardStreamToLoggerAsync(
8676 /// <inheritdoc />
8777 public async Task < int > WaitForExitAsync ( CancellationToken cancellationToken )
8878 {
89- var suppressLogging = _options . SuppressLogging ;
90-
91- if ( ! suppressLogging )
92- {
93- _logger . LogDebug ( "Waiting for process to exit with PID: {ProcessId}" , _process . Id ) ;
94- }
79+ _logger . LogDebug ( "Waiting for process to exit with PID: {ProcessId}" , _process . Id ) ;
9580
9681 await _process . WaitForExitAsync ( cancellationToken ) ;
9782
9883 if ( ! _process . HasExited )
9984 {
100- if ( ! suppressLogging )
101- {
102- _logger . LogDebug ( "Process with PID: {ProcessId} has not exited, killing it." , _process . Id ) ;
103- }
85+ _logger . LogDebug ( "Process with PID: {ProcessId} has not exited, killing it." , _process . Id ) ;
10486 _process . Kill ( false ) ;
10587 }
10688 else
10789 {
108- if ( ! suppressLogging )
109- {
110- _logger . LogDebug ( "Process with PID: {ProcessId} has exited with code: {ExitCode}" , _process . Id , _process . ExitCode ) ;
111- }
90+ _logger . LogDebug ( "Process with PID: {ProcessId} has exited with code: {ExitCode}" , _process . Id , _process . ExitCode ) ;
11291 }
11392
11493 // Explicitly close the streams to unblock any pending ReadLineAsync calls.
@@ -153,32 +132,25 @@ public void Dispose()
153132 _process . Dispose ( ) ;
154133 }
155134
156- private async Task ForwardStreamToLoggerAsync ( StreamReader reader , string identifier , Action < string > ? lineCallback , bool suppressLogging )
135+ private async Task ForwardStreamToLoggerAsync ( StreamReader reader , string identifier , Action < string > ? lineCallback )
157136 {
158- if ( ! suppressLogging )
159- {
160- _logger . LogDebug (
161- "Starting to forward stream with identifier '{Identifier}' on process '{ProcessId}' to logger" ,
162- identifier ,
163- _process . Id
164- ) ;
165- }
137+ _logger . LogDebug (
138+ "Starting to forward stream with identifier '{Identifier}' on process '{ProcessId}' to logger" ,
139+ identifier ,
140+ _process . Id
141+ ) ;
166142
167143 try
168144 {
169145 string ? line ;
170146 while ( ( line = await reader . ReadLineAsync ( ) ) is not null )
171147 {
172- if ( ! suppressLogging )
173- {
174- _logger . LogTrace (
175- "{FileName}({ProcessId}) {Identifier}: {Line}" ,
176- FileName ,
177- _process . Id ,
178- identifier ,
179- line
180- ) ;
181- }
148+ _logger . LogTrace (
149+ "({ProcessId}) {Identifier}: {Line}" ,
150+ _process . Id ,
151+ identifier ,
152+ line
153+ ) ;
182154 lineCallback ? . Invoke ( line ) ;
183155 }
184156 }
0 commit comments