diff --git a/dotnet/src/webdriver/DriverService.cs b/dotnet/src/webdriver/DriverService.cs
index 930cd7948b705..189bd0a94e6ec 100644
--- a/dotnet/src/webdriver/DriverService.cs
+++ b/dotnet/src/webdriver/DriverService.cs
@@ -170,6 +170,14 @@ public int ProcessId
///
protected virtual bool HasShutdown => true;
+ ///
+ /// Gets a value indicating whether process redirection is enforced regardless of other settings.
+ ///
+ /// Set this property to to force all process output and error streams to
+ /// be redirected, even if redirection is not required by default behavior. This can be useful in scenarios where
+ /// capturing process output is necessary for logging or analysis.
+ protected virtual internal bool EnableProcessRedirection { get; } = false;
+
///
/// Gets a value indicating whether the service is responding to HTTP requests.
///
@@ -249,16 +257,23 @@ public void Start()
this.driverServiceProcess.StartInfo.RedirectStandardOutput = true;
this.driverServiceProcess.StartInfo.RedirectStandardError = true;
- this.driverServiceProcess.OutputDataReceived += this.OnDriverProcessDataReceived;
- this.driverServiceProcess.ErrorDataReceived += this.OnDriverProcessDataReceived;
+ if (this.EnableProcessRedirection)
+ {
+ this.driverServiceProcess.OutputDataReceived += this.OnDriverProcessDataReceived;
+ this.driverServiceProcess.ErrorDataReceived += this.OnDriverProcessDataReceived;
+ }
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo);
this.OnDriverProcessStarting(eventArgs);
- // Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks.
this.driverServiceProcess.Start();
- this.driverServiceProcess.BeginOutputReadLine();
- this.driverServiceProcess.BeginErrorReadLine();
+
+ if (this.EnableProcessRedirection)
+ {
+ // Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks.
+ this.driverServiceProcess.BeginOutputReadLine();
+ this.driverServiceProcess.BeginErrorReadLine();
+ }
bool serviceAvailable = this.WaitForServiceInitialization();
@@ -289,7 +304,7 @@ protected virtual void Dispose(bool disposing)
{
this.Stop();
- if (this.driverServiceProcess is not null)
+ if (EnableProcessRedirection && this.driverServiceProcess is not null)
{
this.driverServiceProcess.OutputDataReceived -= this.OnDriverProcessDataReceived;
this.driverServiceProcess.ErrorDataReceived -= this.OnDriverProcessDataReceived;
@@ -335,13 +350,7 @@ protected virtual void OnDriverProcessStarted(DriverProcessStartedEventArgs even
/// The data received event arguments.
protected virtual void OnDriverProcessDataReceived(object sender, DataReceivedEventArgs args)
{
- if (string.IsNullOrEmpty(args.Data))
- return;
- if (_logger.IsEnabled(LogEventLevel.Trace))
- {
- _logger.Trace(args.Data);
- }
}
///
diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
index e00c5c5ce3664..4d9a8bb67f1cb 100644
--- a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
+++ b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
@@ -222,6 +222,11 @@ protected override string CommandLineArguments
}
}
+ ///
+ /// Gets a value indicating whether process output redirection is required.
+ ///
+ protected internal override bool EnableProcessRedirection => LogPath is not null;
+
///
/// Called when the driver process is starting. This method sets up log file writing if a log path is specified.
///