@@ -170,6 +170,14 @@ public int ProcessId
170
170
/// </summary>
171
171
protected virtual bool HasShutdown => true ;
172
172
173
+ /// <summary>
174
+ /// Gets a value indicating whether process redirection is enforced regardless of other settings.
175
+ /// </summary>
176
+ /// <remarks>Set this property to <see langword="true"/> to force all process output and error streams to
177
+ /// be redirected, even if redirection is not required by default behavior. This can be useful in scenarios where
178
+ /// capturing process output is necessary for logging or analysis.</remarks>
179
+ protected virtual internal bool EnableProcessRedirection { get ; } = false ;
180
+
173
181
/// <summary>
174
182
/// Gets a value indicating whether the service is responding to HTTP requests.
175
183
/// </summary>
@@ -249,16 +257,23 @@ public void Start()
249
257
this . driverServiceProcess . StartInfo . RedirectStandardOutput = true ;
250
258
this . driverServiceProcess . StartInfo . RedirectStandardError = true ;
251
259
252
- this . driverServiceProcess . OutputDataReceived += this . OnDriverProcessDataReceived ;
253
- this . driverServiceProcess . ErrorDataReceived += this . OnDriverProcessDataReceived ;
260
+ if ( this . EnableProcessRedirection )
261
+ {
262
+ this . driverServiceProcess . OutputDataReceived += this . OnDriverProcessDataReceived ;
263
+ this . driverServiceProcess . ErrorDataReceived += this . OnDriverProcessDataReceived ;
264
+ }
254
265
255
266
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs ( this . driverServiceProcess . StartInfo ) ;
256
267
this . OnDriverProcessStarting ( eventArgs ) ;
257
268
258
- // Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks.
259
269
this . driverServiceProcess . Start ( ) ;
260
- this . driverServiceProcess . BeginOutputReadLine ( ) ;
261
- this . driverServiceProcess . BeginErrorReadLine ( ) ;
270
+
271
+ if ( this . EnableProcessRedirection )
272
+ {
273
+ // Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks.
274
+ this . driverServiceProcess . BeginOutputReadLine ( ) ;
275
+ this . driverServiceProcess . BeginErrorReadLine ( ) ;
276
+ }
262
277
263
278
bool serviceAvailable = this . WaitForServiceInitialization ( ) ;
264
279
@@ -289,7 +304,7 @@ protected virtual void Dispose(bool disposing)
289
304
{
290
305
this . Stop ( ) ;
291
306
292
- if ( this . driverServiceProcess is not null )
307
+ if ( EnableProcessRedirection && this . driverServiceProcess is not null )
293
308
{
294
309
this . driverServiceProcess . OutputDataReceived -= this . OnDriverProcessDataReceived ;
295
310
this . driverServiceProcess . ErrorDataReceived -= this . OnDriverProcessDataReceived ;
@@ -335,13 +350,7 @@ protected virtual void OnDriverProcessStarted(DriverProcessStartedEventArgs even
335
350
/// <param name="args">The data received event arguments.</param>
336
351
protected virtual void OnDriverProcessDataReceived ( object sender , DataReceivedEventArgs args )
337
352
{
338
- if ( string . IsNullOrEmpty ( args . Data ) )
339
- return ;
340
353
341
- if ( _logger . IsEnabled ( LogEventLevel . Trace ) )
342
- {
343
- _logger . Trace ( args . Data ) ;
344
- }
345
354
}
346
355
347
356
/// <summary>
0 commit comments