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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend documentation and samples #157

Open
martincostello opened this issue Aug 6, 2020 · 5 comments
Open

Extend documentation and samples #157

martincostello opened this issue Aug 6, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@martincostello
Copy link
Owner

Based on #156, the documentation could be expanded (and the samples extended) to show usage of the logger with a test fixture, rather than just in a standalone test.

Also consider an example that supports parallel execution of tests without bleeding the logger between them.

@martincostello martincostello added the enhancement New feature or request label Aug 6, 2020
@martincostello martincostello added this to the Future milestone Aug 6, 2020
@martincostello martincostello self-assigned this Aug 6, 2020
@stale stale bot added the wontfix This will not be worked on label Oct 4, 2020
@martincostello martincostello removed the wontfix This will not be worked on label Oct 4, 2020
@stale stale bot added the wontfix This will not be worked on label Dec 19, 2020
@martincostello martincostello removed the wontfix This will not be worked on label Dec 19, 2020
@stale stale bot added the wontfix This will not be worked on label Mar 29, 2021
@martincostello martincostello removed the wontfix This will not be worked on label Mar 29, 2021
@stale stale bot added the wontfix This will not be worked on label May 26, 2021
@martincostello martincostello removed the wontfix This will not be worked on label May 26, 2021
@stale stale bot added the wontfix This will not be worked on label Jul 21, 2021
@martincostello martincostello removed the wontfix This will not be worked on label Jul 21, 2021
@stale stale bot added the wontfix This will not be worked on label Nov 28, 2021
@martincostello martincostello removed the wontfix This will not be worked on label Nov 28, 2021
Repository owner deleted a comment from stale bot Jan 27, 2022
Repository owner deleted a comment from stale bot Jan 27, 2022
Repository owner deleted a comment from stale bot Jan 27, 2022
Repository owner deleted a comment from stale bot Jan 27, 2022
Repository owner deleted a comment from stale bot Jan 27, 2022
Repository owner deleted a comment from stale bot Jan 27, 2022
@mderriey
Copy link

to show usage of the logger with a test fixture

I'd be super interested in this.

Usually, I set up a collection fixture where the service collection / test server is created once, then all test classes use that same instance to run tests.

My understanding is that ITestOutputHelper is only injectable in test classes constructors, and I don't think we can "inject" loggers after the service provider is built.

Am I missing something?

@martincostello
Copy link
Owner Author

That's correct, but it's possible to still use it with a shared fixture with the use of the ITestOutputHelperAccessor interface and a bit of boilerplate in a base class. This just isn't explicitly spelled out in the docs here yet 😃.

From an example in one of my own projects.

  1. The shared fixture implements ITestOutputHelper and provides a mechanism to set and clear the ITestOutputHelper.
  2. A base class for the tests sets and clears the output helper.
  3. Individual test classes pass through the output helper to the base class.

xunit then does the rest of the heavy lifting for you. The only downside (which is inherent to how xunit works) is that you can't have multiple tests running in parallel with the same fixture, as they'll otherwise be fighting over the current output helper. Maybe you could wrap it and have multiple helpers and cycle them based on the current thread/fixture or something and delegate it via a reference to overcome that, but it's not something I've tried.

@mderriey
Copy link

Very clean implementation, I like it a lot.

I usually have base classes as well to reset the database between each test.

Thanks heaps!

@woha
Copy link

woha commented Sep 13, 2023

Is there a way to set the log level?
Looks like it is set to information by default and I’m missing the debug and trace output.

Thank you, Martin

@martincostello
Copy link
Owner Author

All levels except None are logged by default unless you provide a custom Filter method:

public bool IsEnabled(LogLevel logLevel)
{
if (logLevel == LogLevel.None)
{
return false;
}
return Filter(Name, logLevel);
}

My guess would be your application is configured to not log whatever you're looking for at Debug or Trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants