Dependency Injection Logging: AddDebug() works but AddSerilog() doesn't.
Hi, I am using Microsoft.Extensions.DependencyInjection and Serilog
I invoke the following on a serviceCollection:
This is how I get a logger from the constructor:
I see that message appear in the debug window but Serilog does not make the file, however if I change
to
Serilog actually creates the file, but it doesn't write anything to it, which makes me think I actually am using this correctly? I found something that says you need to convert the Serilog's logger to a Microsoft.Extensions.Logging.ILogger, but that solution is for ASP.NET and I'm not sure if it applies since that HostBuilder is not used in WPF
Stack Overflow
Serilog does not output logs into the txt file
Im using dotnet worker service (.net 5)
I integrated serilog as well as enrichers and sinks.
But for some reason I dont see any outputs into my files logs.
Here is my appsettings.json
{
"
2 Replies
it seems wrong that you're trying to add 2 different logging services, if you want logging to the debug console that should be configured as a serilog sink and not as a separate logging service
e.g.
loggerConfig.WriteTo.Debug();
I primarily want a log file, but Serilog on it's own didn't work. nothing changes when I remove
I only added this line afterwards to see if the logger actually worked, since I couldn't get Serilog to work