-
Notifications
You must be signed in to change notification settings - Fork 207
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
Should I use Microsoft.Extensions.Logging.ILogger<T> or Serilog.ILogger? #104
Comments
In all of my work, I only use types from the Very rarely have I been wanting Serilog-specific functionality elsewhere in my codebase. |
I'm the opposite way around - I only set up the Microsoft.Extensions.* interfaces so that the framework can have access to the logging pipeline. In application code, I use Serilog's In the end I think it's a matter of taste. I prefer the shorter method names and lack of generic type arguments in the Serilog interfaces. I also dislike having to clutter every constructor with YMMV! Serilog is currently available in all environments supported by Microsoft.Extensions.Logging that I'm aware of, plus several more. :-) |
You can accept
I use T4 for generating constructors for DI a lot, actually - which helps with the ergonomics of having more than a few constructor parameters. It's available here if you're interested: https://gist.github.com/Jehoel/f395a419e9d70c4a718284fdfeef007b - it has special-handling for logging as well. |
Thank you all. I'm going with Serilog's ILogger and static |
Do not forget that you can go the third way - do not use either the first or the second. Creating your own abstraction is a good option if you are going to build a large system with your own library stack. In this case, by creating your own dependency, you protect against possible problems when changing dependency versions. The specific implementation of logging is placed in a separate package. I mean implementation since |
How to use Serilog ILogger, can anyone show me the way ? Cause in every tutorial and all around , everybody are using Microsoft.Extensions.Logging.ILogger and injecting ILogger to log. How to inject Serilog ILogger and use in other class? |
@utsabshrestha You should ask that on StackOverflow |
@Jehoel why should ask on stackoverflow? it should be in document or wiki. it is a common use case, should not ask in stackoverflow. |
Lucky for you all somebody already did ask it on Stack Overflow. |
All examples of using Serilog with ASP .NET Core I see, are using Microsoft's logging interface, instead of Serilog's interface.
Is that the recommended approach now? If yes, why is that?
The text was updated successfully, but these errors were encountered: