`Serilog:Using` Check Seems Unnecessarily Restrictive
See original GitHub issueFor an AOT-published application on .NET 8, I have the following configuration (in the Microsoft.Extensions.Configuraation sense):
{
"Serilog": {
"MinimumLevel": "Debug"
}
}
…and the rest of the Serilog configuration is done in C# code. I would like be able to change this log level at runtime. However, Serilog.Settings.Configuration fails at runtime when the only assembly to search is “Serilog”. Because of how that is done, the following expected workarounds do not solve the problem:
{
"Serilog": {
"Using": [],
"MinimumLevel": "Debug"
}
}
{
"Serilog": {
"Using": null,
"MinimumLevel": "Debug"
}
}
{
"Serilog": {
"Using": ["Serilog"],
"MinimumLevel": "Debug"
}
}
All of which fail at runtime with the same error message: “No Serilog:Using configuration section is defined and no Serilog assemblies were found. This is most likely because the application is published as single-file.” and so on.
In order to continue testing AOT publication, I have to configure like this:
{
"Serilog": {
"Using": ["<name of entry assembly>"],
"MinimumLevel": "Debug"
}
}
…but this is undesirable since we’d have to put the name of the entry assembly in the configuration for each application. Is there or can there be a way to give Serilog.Settings.Configuration a positive signal that the single assembly it found is OK?
Issue Analytics
- State:
- Created 2 months ago
- Comments:11 (8 by maintainers)
Top Related StackOverflow Question
Actually I prefer Nicholas’ proposal to check if sections other than
MinimumLevelexist and throw only if that’s the case. It also solves this issue but without forcing users to add aUsingsection in the configuration.I’ll have a look at the tests when I’m back from vacation in a few days.
Another option might be to only trigger the check if sections other than
MinimumLevelexist?