`Serilog:Using` Check Seems Unnecessarily Restrictive

See original GitHub issue

For 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:closed
  • Created 2 months ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
0xcedcommented, Jul 30, 2023

Actually I prefer Nicholas’ proposal to check if sections other than MinimumLevel exist and throw only if that’s the case. It also solves this issue but without forcing users to add a Using section in the configuration.

I’ll have a look at the tests when I’m back from vacation in a few days.

1reaction
nblumhardtcommented, Jul 27, 2023

Another option might be to only trigger the check if sections other than MinimumLevel exist?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Identity Server Providing too many logs in Serilog
My problem is that the Identity Server is writing a lot of logs I find unnecessary, and I thought I had set the...
Read more >
How to use advanced Serilog features in ASP.NET Core ...
In the “Configure your new project” window, specify the name and location for the new project. Optionally check the “Place solution and project ......
Read more >
Don't display unnecessary warning if no target framework ...
BTW, I'm noticing this on transitive dependencies that don't apply for the target framework. I get this via Zlib.Portable pulled by FSharp.Data ...
Read more >
Serilog Best Practices - Ben Foster
Serilog is a structured logging library for Microsoft .NET and has become the preferred logging library for .NET at Checkout.com.
Read more >
Serilog event log appsettings. c#; asp. MinimumLevel ...
Part 1 - Reducing log verbosity with Serilog RequestLogging (this post) Part 2 ... Yeah, but you still don't get conditional logging, some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found