Closed
Description
Not really an issue, but I've just experimented with using appsettings to configure the logger. I don't know if this is something worth adding in or not, so I'll just include a few code snippets.
Happy to create a PR if it's valuable.
First off, in the extensions
public static IWebHostBuilder UseSerilogLogger(this IWebHostBuilder builder)
{
if (builder == null) throw new ArgumentNullException(nameof(builder));
builder.ConfigureServices((context, collection) =>
collection.AddSingleton<ILoggerFactory>(new LoggerFactory(context.Configuration))
);
return builder;
}
Then in the factory
public LoggerFactory(IConfiguration configuration)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
_provider = new SerilogLoggerProvider();
}
And finally my settings
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console"
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
Metadata
Metadata
Assignees
Labels
No labels