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

Logging on Service Registration #7965

Closed
hikalkan opened this issue Mar 5, 2021 · 0 comments
Closed

Logging on Service Registration #7965

hikalkan opened this issue Mar 5, 2021 · 0 comments

Comments

@hikalkan
Copy link
Member

hikalkan commented Mar 5, 2021

Currently, we can't write logs in ConfigureServices since the dependency injection phase has not been completed and the ILogger can be resolved once dependency injection completed.

We are introducing IInitLogger that can be used in DI registration phase, in ConfigureServices.
When you have IServiceCollection services, you can use services.GetInitLogger() to obtain a reference to the IInitLogger. Then you can write logs like;

var logger = services.GetInitLogger();
logger.Log(LogLevel.Information, "my log message..."); //gets optional `Exception` as the last argument.

Logs are collected in a collection and written to the actual ILogger once the DI registration phase completes and we are able to resolve the ILogger.

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

1 participant