-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] Enabling drivers to set log to console. #16097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This will be false by default, following what the .NET bindings have usually done. Helps with #12273
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
LogPath takes precedence anyway.
Messages will be shown to the console using the Logger functionality. Adding a test that listens to the logger and checks that logs are being sent to console. Fixing an issue when sending the log to a file, as the OnDriverProcessStarted method in the base class was not being invoked.
Internal variable to avoid using the stream when logs are sent to a file. Not exposed to the user.
Co-authored-by: Nikolay Borisenko <[email protected]>
Please see minimal example how to capture output from process. Probably it helps. var service = new MyService();
service.Start();
class MyService
{
public void Start()
{
var process = new Process();
process.StartInfo.FileName = "ping";
process.StartInfo.Arguments = "google.com";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += OnDataReceived;
process.ErrorDataReceived += OnDataReceived;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
protected virtual void OnDataReceived(object sender, DataReceivedEventArgs args)
{
if (string.IsNullOrEmpty(args.Data))
return;
// This method can be used to handle data received from the process
Console.WriteLine($"Data received: {args.Data}");
}
} |
Thanks. I did try the approach and made changes to use the idea you suggest, but then I end up with errors like this one:
Do you have any suggestions? I am only trying to log messages to console here, not even trying to log to a file yet. |
Please disregard the message above, I found out why this happens. |
@diemol can I help here and implement it from scratch if you don't mind? |
@nvborisenko, I have not seen your comment before. I just pushed the code I had locally using the approach you recommended. Please feel free to create a PR from scratch or review this. Bear in mind that the changes to |
I quickly implemented these changes, and observed you did it already in pretty similar way. Let's continue here with your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, long await feature/issue is now resolved! Good work.
User description
This will be false by default, following what the .NET bindings have usually done.
🔗 Related Issues
Helps with #12273
Should fix #15785
💥 What does this PR do?
It enables users to send driver logs to the console, disabled by default.
🔧 Implementation Notes
💡 Additional Considerations
I could only test it manually by creating a .NET app and using the build as a dependency.
@nvborisenko, could you please help me check this?
🔄 Types of changes
PR Type
Enhancement
Description
Add
LogToConsole
property toDriverService
classEnable driver process console output logging (disabled by default)
Handle mutual exclusivity between
LogToConsole
andLogPath
in FirefoxDiagram Walkthrough
File Walkthrough
DriverService.cs
Add LogToConsole property and output redirection
dotnet/src/webdriver/DriverService.cs
LogToConsole
boolean property with XML documentationLogToConsole
is false
FirefoxDriverService.cs
Handle LogToConsole and LogPath mutual exclusivity
dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
LogToConsole
andLogPath
LogToConsole
whenLogPath
is specified