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

Configurable logging #445

Closed
RoadTrain opened this issue Sep 6, 2021 · 6 comments
Closed

Configurable logging #445

RoadTrain opened this issue Sep 6, 2021 · 6 comments

Comments

@RoadTrain
Copy link

RoadTrain commented Sep 6, 2021

Hello! Thanks for the great library.

I've been using it in my application for a while via nuget package ReportGenerator.Core, and now I wonder how to set up logging in a way that internal library logs are not printed to console, but instead redirected to the application-level logger (I'm using Serilog).

Is there a way to configure that? From what I see from source code, class loggers are resolved once, and are stored in static fields, which will prevent runtime reconfiguration.

Am I missing something?

@danielpalme
Copy link
Owner

That's correct. The logger is currently not configurable.

@RoadTrain
Copy link
Author

@danielpalme Would you welcome contributions to make it configurable? Maybe you already have a vision of how it should be done?

@danielpalme
Copy link
Owner

Sorry, my initial reply was wrong or at least not complete.

You can implement a custom Logger and custom LoggerFactory.

Then you can register your custom factory:

LoggerFactory.Configure(new MyCustomLoggerFactory());

That way you should be able to write a custom adapter to your logging system.

@RoadTrain
Copy link
Author

RoadTrain commented Sep 8, 2021

Thanks, I'll give it a try.
What do you think of extending this class with another method like:

LoggerFactory.Configure(Action<VerbosityLevel, string> logDelegate);

So that consumers would need to only provide a logger delegate instead of implementing their own ILogger and ILoggerFactory?

If you're not against such an approach, I can draft a pull request.

@danielpalme
Copy link
Owner

Sure, that should be no problem.

@danielpalme
Copy link
Owner

I created a draft here: #446
What do you think?

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