Skip to content

Serilog example fixed #1

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Serilog example fixed #1

wants to merge 3 commits into from

Conversation

dazinator
Copy link

Check out the change in Program.cs.
Dotnettency depends upon Microsoft.Extension.Logging.ILogger to be injected, so microsoft logging must be added and configured prior to startup. Serilog has some docs that show you how it can hook up with microsofts abstraction so it can support this scenario.. but I found the mechanism suggested in the serilog readme a little problematic.

UseSerilog() (in Program.cs) causes the problem with dotnettency seemingly because it relies on a constructed IServiceProvIder instance, to then find all the registered ILogger's (microsoft ones) and set up it's own factory. Trouble is needs that factory to be registered ahead of the IServiceProvider being constructed. This is because the implementation of the IServiceProvider that get's constructed is actually dotnettency's `IServiceProvider implementation - and in it's constructor it requires an ILogger to be injected - which requires a ILoggerFactory to be registered. However Serilog registers it's own ILoggerFactory that requires an IServiceProvider to be created first.. and thus the recursive loop that Autofac was complaing about..

Anyway alternative way of registering serilog seems to work nicely.

Sorry about the noise in this PR, I also updated the dotnettency dependencies to use the latest 2.0.0-alpha version from dev branch.

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

Successfully merging this pull request may close these issues.

1 participant