SteeltoeOSS / Samples

Steeltoe samples and reference application collection
https://steeltoe.io/
Apache License 2.0
641 stars 250 forks source link

Serilog.ILogger is not registered in IoC #308

Closed lastsignal closed 8 months ago

lastsignal commented 8 months ago

Is your feature request related to a problem? Please describe.

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 with Microsoft.Extensions.Logging.ILogger

using Serilog;
using Steelto.Extensions.Configuration.CloudFoundry;
using Steeltoe.Extensions.Logging.DynamicSerilog;
using Steeltoe.Management.Endpoint;
using Web.Application.Logging;

var builder = WebApplication.CreateBuilder(args);

builder.AddCloudFoundryConfiguration();

builder.AddDynamicSerilog(configurationLogger: (_, lg) =>
{
    lg.Initialize();
});

builder.WebHost.AddAllActuators();
builder.Services.AddControllers();
builder.Services.AddSingleton(Log.Logger);

var app = builder.Build();

app.MapControllers();

app.Run();

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 to SilentLogger;

I tried different way to get access to serilogLogger from the library before it turns to FrameworkLogger, no luck!

Any suggestion?

Dan

bart-vmware commented 8 months ago

Duplicate of https://github.com/SteeltoeOSS/Steeltoe/issues/1203.

lastsignal commented 8 months ago

please close this on since the actual issue is in https://github.com/SteeltoeOSS/Steeltoe/issues/1203 Thanks