serilog / serilog-settings-configuration

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

Init-only setters #383

Closed chrbanx closed 1 year ago

chrbanx commented 1 year ago

v7.0.0 deprecates some extensions and adds ConfigurationReaderOptions. This has some properties with init-only setters, which require C# language version 9. The library publishes support for net462/netstandard2.0 though, which use langversion 7.3, and compilation fails with Error CS8400 Feature 'init-only setters' is not available.

nblumhardt commented 1 year ago

Thanks for the note; needs some thought. https://github.com/dotnet/csharplang/issues/3376 seems to be discussing roughly this issue.

0xced commented 1 year ago

Indeed, all .NET Framework targets use C# 7.3 as the default. You can update the language version by adding a LangVersion element in your csproj.

For example:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net462</TargetFramework>
    <LangVersion>10.0</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
  </ItemGroup>

</Project>

Is this an issue for you?

0xced commented 1 year ago

Were you able to solve your issue by explicitly setting LangVersion to 10.0?

chrbanx commented 1 year ago

Were you able to solve your issue by explicitly setting LangVersion to 10.0?

Yes, thanks, it does work. It's slightly suboptimal as the newer language versions are officially unsupported with .NET Framework, so care needs to be taken to avoid using other new language features that aren't as compatible with the runtime. Not a major concern though.