Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: .NET LogFileHandler not writing any logs #13839

Open
MJB222398 opened this issue Apr 18, 2024 · 6 comments
Open

[馃悰 Bug]: .NET LogFileHandler not writing any logs #13839

MJB222398 opened this issue Apr 18, 2024 · 6 comments

Comments

@MJB222398
Copy link

MJB222398 commented Apr 18, 2024

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?

private const string LogFilePath = "C:\\Users\\MyName\\Downloads\\Gubbins\\logs.log";

[Test]
public async Task Test1()
{
    EdgeOptions edgeOptions = new();
    edgeOptions.AddArgument("--start-maximized");
    edgeOptions.AddArgument("--disable-dev-shm-usage");
    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();
    }
}

Relevant log output

I wish I could

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

Copy link

@MJB222398, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

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!

@nvborisenko
Copy link
Member

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.

@MJB222398
Copy link
Author

@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?

@nvborisenko
Copy link
Member

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.

@MJB222398
Copy link
Author

MJB222398 commented Apr 22, 2024

@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

@MJB222398
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants