From c05d0e27ee84ddb149f2c7099839f424013b5617 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 26 Sep 2025 21:58:17 +0300 Subject: [PATCH 1/3] [dotnet] Conditionally enable driver service process output redirection --- dotnet/src/webdriver/DriverService.cs | 33 ++++++++++++------- .../webdriver/Firefox/FirefoxDriverService.cs | 5 +++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/dotnet/src/webdriver/DriverService.cs b/dotnet/src/webdriver/DriverService.cs index 930cd7948b705..1b3354a28b079 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 or sets a value indicating whether process redirection is enforced regardless of other settings. + /// + /// Set this property to to force all process output and input 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. /// From e66174680901c3806e5286687948db889c5eb547 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 26 Sep 2025 22:14:10 +0300 Subject: [PATCH 2/3] Update docs --- dotnet/src/webdriver/DriverService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/DriverService.cs b/dotnet/src/webdriver/DriverService.cs index 1b3354a28b079..f2cb4b9ddf175 100644 --- a/dotnet/src/webdriver/DriverService.cs +++ b/dotnet/src/webdriver/DriverService.cs @@ -171,7 +171,7 @@ public int ProcessId protected virtual bool HasShutdown => true; /// - /// Gets or sets a value indicating whether process redirection is enforced regardless of other settings. + /// Gets a value indicating whether process redirection is enforced regardless of other settings. /// /// Set this property to to force all process output and input streams to /// be redirected, even if redirection is not required by default behavior. This can be useful in scenarios where From 39f4bcec15784b297f670c8cc923ecc2d2de1ccf Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 26 Sep 2025 22:28:52 +0300 Subject: [PATCH 3/3] Update DriverService.cs --- dotnet/src/webdriver/DriverService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/DriverService.cs b/dotnet/src/webdriver/DriverService.cs index f2cb4b9ddf175..189bd0a94e6ec 100644 --- a/dotnet/src/webdriver/DriverService.cs +++ b/dotnet/src/webdriver/DriverService.cs @@ -173,7 +173,7 @@ public int ProcessId /// /// Gets a value indicating whether process redirection is enforced regardless of other settings. /// - /// Set this property to to force all process output and input streams to + /// 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;