Closed lastsignal closed 11 months ago
Hi @lastsignal, thanks for asking.
I'm unsure if Steeltoe supports using Serilog.ILogger
instead of Microsoft.Extensions.Logging.ILogger
.
@hananiel Can you shed some light on this?
@lastsignal Is there any particular reason you prefer or need to use the Serilog-specific logger instead of the Microsoft abstraction?
@bart-vmware, Several reasons:
Serilog.ILogger
and Steeltoe v2
that need to be upgraded. Serilog.ILogger
has some features that make the log statement simpler.
All the features can be implemented in different way in the Framework Logger. But changing existing apps, with a lot of unit tests, wouldn't be practical.
I think what can help is to expose the Serilog Logger from the provider: https://github.com/SteeltoeOSS/Steeltoe/blob/9781c9ff24757dfd447dbedcae7fe4c7a82b8b55/src/Logging/src/DynamicSerilog/SerilogDynamicProvider.cs#L56
Thanks
In addition, 'Log.Logger' is very handy in many places like static classes that don't have DI. This package sets Log.Logger
to SilentLogger
. Maybe setting Log.Logger
to _serilogLogger
in the code about is an option?
After all, this package is called DynamicSerilog
. It gives the impression that it completely supports Serilog.
Cheers
@lastsignal I understand the convenience that using the static logger provides. Steeltoe's DynamicSerilog
package allows configuration to be changed at runtime. Steeltoe does this by using the infrastructure that targets Microsoft ILogger/ILoggerFactory abstractions. Using the static Serilog logger would bypass the filter mechanism Steeltoe uses to provide dynamic LogLevel
filters (changed via logger actuator). So even though the configured logger would be exposed, it would only respect the configuration provided to it at startup. All other changes will be lost. If you do not need that, then you can directly use the Serilog Logger directly.
@hananiel, I understand the trade off. But can we at least have Serilog.ILogger registered in the IoC? Can it be done right after the line that I mentioned above?
@lastsignal I am unclear on why you need the Steeltoe extension to do this- which features of Steeltoe are you leveraging by doing this? Do you want to create a sample app we can walk through. I am also available for a zoom call to discuss if that will be better. We can continue via the Steeltoe slack channel
As Hananiel explained, Steeltoe provides changing log levels at runtime using Serilog when utilizing the Microsoft.Extensions.Logging.ILogger
infrastructure. If there's no need for dynamically changing log levels, feel free to use Serilog directly without its Steeltoe facilities.
Closing this issue, as I think there's nothing we can do. Please let us know if you need this to be reopened.
Working with a simple .NET 6 application like the following. I am not able to get a use of
Serilog.ILogger
in my code. Everything else work perfectly withMicrosoft.Extensions.Logging.ILogger
In the above code
Initialize()
just configures the logger with its sinks.If I don't add the line
builder.Services.AddSingleton(Log.Logger);
,Serilog.ILogger
will be null. When I add it, it will resolved toSilentLogger
;I tried different way to get access to serilogLogger from the library before it turns to FrameworkLogger, no luck!
Any suggestion?
Dan