Microsoft.NET.Sdk.Web global using statements break Serilog/NLog/log4net consumers on upgrade
See original GitHub issueFrom https://github.com/dotnet/templating/issues/3359#issuecomment-914693605
The .NET 6 version of Microsoft.NET.Sdk.Web
introduces a default global using statement for Microsoft.Extensions.Logging
. This brings MEL’s ILogger
into scope everywhere, breaking existing code that uses Serilog’s (or another framework’s) ILogger
interface, with errors like:
/home/pi/dl/nix/seq/tmp/ubuntu.20.04-arm64/src/Seq/Server/Tasks/TaskRunner.cs(15,18): error CS0104: 'ILogger' is an ambiguous reference between 'Microsoft.Extensions.Logging.ILogger' and 'Serilog.ILogger' [/home/pi/dl/nix/seq/tmp/ubuntu.20.04-arm64/src/Seq/Seq.csproj]
The breakage can be worked around by adding <EnableDefaultGlobalUsing>false</EnableDefaultGlobalUsing>
or similar to the project’s CSPROJ file, but this is a pretty nasty papercut that penalizes users for choosing a logging library other than Microsoft’s. The chore will be particularly onerous because of the number of projects affected (and volume of errors within these projects).
I’d also expect that many users will turn to the Serilog project asking for guidance or reporting the breakage as a bug, since the default assumption people make when encountering an issue like this is that “Serilog is broken on .NET 6” - which increases our support burden 😃
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top GitHub Comments
This might be another alternative:
OR
Tell customers to introduce a global alias for serilog’s ILogger as an override. (This can also be scoped to a file if that is too global).
Note that some users (e.g. my team) use Serilog as an output system, but use
Microsoft.Extensions.Logging
abstractions for most of the actual logging. It would be confusing to deal with the NuGet reference to Serilog causingILogger
to be switched from one definition to the other.That said; I’ll probably be disabling global usings everywhere, anyway.