-
Notifications
You must be signed in to change notification settings - Fork 34
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
UseSerilog Infinite loop: ReadFrom.Services + KinesisFirehoseSink #48
Comments
I am experiencing a similar issue when using |
I just ditched the two-stage init. I came to the conclusion it's not that important to me and creates more issues than it solves. Initialization changes infrequently, errors outside development are rare, and when they do happen I make sure they fail spectacularly and if need be I can look at a file log on the host. I don't need them sent to kinesis. |
I believe I bump into the same issue - custom service that needs Sampleusing Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<FooService>();
builder.Host.UseSerilog((context, services, configuration) =>
{
var service = services.GetRequiredService<FooService>();
});
builder.Build().Run();
public class FooService
{
private readonly ILogger<FooService> _logger;
public FooService(ILogger<FooService> logger)
=> _logger = logger;
} Setup
IssueThis gets stuck in an infinite loop like OP described. In me specific case thread dies after 252 iterations and the app never starts... Shouldn't a bootstrap logger be used initially in such case - this would've solved the isssue I believe? Addional infoThe same exact thing happens when using pre-net6 configuration via using Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.UseSerilog((context, services, configuration) =>
{
var service = services.GetRequiredService<FooService>();
})
.Build()
.Run();
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<FooService>();
}
public void Configure(IApplicationBuilder app) { }
} Workaround (kinda)Well, this is far far from ideal, but I've come up with builing
// ...
var serviceProvider = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.Build()
.Services;
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.UseSerilog((context, _, configuration) =>
{
var service = serviceProvider.GetRequiredService<FooService>();
})
.Build()
.Run();
// ... |
If you use the
Two-stage initialization
from here:https://github.com/serilog/serilog-aspnetcore#two-stage-initialization
and configure a KinesisFirehoseSink like so...
You end up in an infinite loop because the
IAmazonKinesisFirehose
factory is looking for anILoggerFactory
.The text was updated successfully, but these errors were encountered: