@@ -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 ( "{FileName} failed to start 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 ( "{FileName}({ProcessId}) started in {WorkingDirectory}" , FileName , _process . Id , _process . StartInfo . WorkingDirectory ) ;
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,36 +76,25 @@ 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 ( "{FileName}({ProcessId}) waiting for exit" , FileName , _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 ( "{FileName}({ProcessId}) has not exited, killing it" , FileName , _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 ( "{FileName}({ProcessId}) exited with code: {ExitCode}" , FileName , _process . Id , _process . ExitCode ) ;
11291 }
11392
11493 // Explicitly close the streams to unblock any pending ReadLineAsync calls.
11594 // In some environments (particularly CI containers), the stream handles may not
11695 // be automatically closed when the process exits, causing ReadLineAsync to block
11796 // indefinitely. Disposing the streams forces them to close.
118- _logger . LogDebug ( "Closing stdout/stderr streams for PID: {ProcessId}" , _process . Id ) ;
97+ _logger . LogDebug ( "{FileName}({ProcessId}) closing stdout/stderr streams" , FileName , _process . Id ) ;
11998 _process . StandardOutput . Close ( ) ;
12099 _process . StandardError . Close ( ) ;
121100
@@ -130,11 +109,11 @@ public async Task<int> WaitForExitAsync(CancellationToken cancellationToken)
130109 var completedTask = await Task . WhenAny ( forwardersCompleted , forwarderTimeout ) ;
131110 if ( completedTask == forwarderTimeout )
132111 {
133- _logger . LogWarning ( "Stream forwarders for PID { ProcessId} did not complete within timeout after stream close. Continuing anyway." , _process . Id ) ;
112+ _logger . LogWarning ( "{FileName}({ ProcessId}) stream forwarders did not complete within timeout after stream close" , FileName , _process . Id ) ;
134113 }
135114 else
136115 {
137- _logger . LogDebug ( "Pending forwarders for PID completed: {ProcessId}" , _process . Id ) ;
116+ _logger . LogDebug ( "{FileName}({ProcessId}) forwarders completed" , FileName , _process . Id ) ;
138117 }
139118 }
140119
@@ -153,23 +132,21 @@ 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+ "{FileName}({ProcessId}) starting to forward {Identifier} stream" ,
139+ FileName ,
140+ _process . Id ,
141+ identifier
142+ ) ;
166143
167144 try
168145 {
169146 string ? line ;
170147 while ( ( line = await reader . ReadLineAsync ( ) ) is not null )
171148 {
172- if ( ! suppressLogging )
149+ if ( _logger . IsEnabled ( LogLevel . Trace ) )
173150 {
174151 _logger . LogTrace (
175152 "{FileName}({ProcessId}) {Identifier}: {Line}" ,
@@ -185,7 +162,7 @@ private async Task ForwardStreamToLoggerAsync(StreamReader reader, string identi
185162 catch ( ObjectDisposedException )
186163 {
187164 // Stream was closed externally (e.g., after process exit). This is expected.
188- _logger . LogDebug ( "Stream forwarder completed for {Identifier} - stream was closed" , identifier ) ;
165+ _logger . LogDebug ( "{FileName}({ProcessId}) {Identifier} stream forwarder completed - stream was closed" , FileName , _process . Id , identifier ) ;
189166 }
190167 }
191168}
0 commit comments