Open MJB222398 opened 5 months ago
@MJB222398, thank you for creating this issue. We will troubleshoot it as soon as we can.
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template
label.
If the issue is a question, add the I-question
label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted
label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-*
label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer
label.
Thank you!
This issue is logical issue. Currently, each Logger
has its own Level
(what is good). Particularly in this case, Logger
captured default level (INFO) before creating a new LogContext
. To resolve this issue we need to allow keeping a map between loggers and its levels in each LogContext
separately.
@MJB222398, As a workaround I can propose to initiate new webdriver in LogContext
scope:
using (var logContext = ...)
{
var driver = new ...
}
It is not a solution, selenium library should resolve it.
@nvborisenko Thanks for your answer, yes I can see doing as suggested will produce the expected logs. I can also do this:
[Test]
public async Task Test1()
{
EdgeOptions edgeOptions = new();
edgeOptions.AddArgument("--start-maximized");
edgeOptions.AddArgument("--disable-dev-shm-usage");
Log.SetLevel(LogEventLevel.Trace);
var driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), edgeOptions.ToCapabilities(), TimeSpan.FromSeconds(30));
using (var logContext = Log.CreateContext(LogEventLevel.Trace).Handlers.Add(new FileLogHandler(LogFilePath)))
{
driver.Navigate().GoToUrl("https://www.google.co.uk");
driver.Quit();
}
}
Which I I think is what you are saying you would expect.
Unrelated, I would like to be able to pass in a FileMode
option (or an abstraction of this depending on your architectural style) for this FileLogHandler constructor as for me I want to overwrite the file each test rather than just append. Is this something you would support?
The aim is your original piece of code should work, you use the logging correctly.
Unrelated, I think it is good idea to introduce some basic features out of the box in core project like overwriting file instead of appending. Please post new issue to track it separately.
@nvborisenko while I was able to get it to work with the reduced code above I am still having trouble getting it to actually work in my complete production ready solution. Spent 4 hours trying to see the problem, I shall retire for now and look into that again tomorrow and report back to you.
I will raise a separate issue for the file overwriting yes
@nvborisenko Ok, figured it out, the logging context does not work if I create it in an asynchronous method. I have raised #13859 for this.
Also raised #13860 for the file overwriting feature
What happened?
I want to use the FileLogHandler to write out driver logs to the filesystem. When I try this I see the log file gets created on disc but nothing is ever written to it.
How can we reproduce the issue?
Relevant log output
Operating System
Windows 10
Selenium version
4.19.0
What are the browser(s) and version(s) where you see this issue?
All
What are the browser driver(s) and version(s) where you see this issue?
All
Are you using Selenium Grid?
I am: 4.18.0-20240220