serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
446 stars 129 forks source link

Annotate Serilog.Settings.Configuration as not trim-compatible #371

Open agocke opened 1 year ago

agocke commented 1 year ago

Unfortunately I don't have any good news for this library. It looks like the fundamental concept, loading arbitrary types by name from arbitrary assemblies, configured by the user at run-time, is fundamentally incompatible with trimming and AOT.

This at least marks it as such. Supporting a feature set like the one provided here would likely require a source generator, or build-time code generation phase.

agocke commented 1 year ago

PolySharp is currently missing RequiresAssemblyFiles (https://github.com/Sergio0694/PolySharp/issues/65) but the author is very responsive, so I'll wait for them to add it and then I'll pull in a new version.

agocke commented 1 year ago

I should also mention -- it's worth considering if this space should have an AOT-compatible solution. I think a source generator would probably be necessary.

nblumhardt commented 1 year ago

@agocke just thinking about:

I should also mention -- it's worth considering if this space should have an AOT-compatible solution. I think a source generator would probably be necessary.

Would this have much benefit over just relying on the C# configuration API? (The C# API can still pull values from appsettings.json directly, where parameters need to vary at deployment time..)

agocke commented 1 year ago

This is a good point -- I was thinking that theoretically you could use a source generator to parse the file, and then construct an equivalent graph at compile time. But that would create a potentially confusing situation where people may believe they can change the file after deployment and get different behavior -- and they can't. Making this a code-only configuration system seems like the right idea.