dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.24k stars 1.35k forks source link

Integrate Microsoft.Extensions.Logging ILogger with MSBuild's logging abstractions #10757

Open baronfel opened 1 month ago

baronfel commented 1 month ago

Ok, thanks - that makes sense. Crazy that this was working for so long. Not sure what broke it, but clear I was depending on something I should not.

Separately, there is basically no bridge to Microsoft DI, which makes writing MSBuild tasks that reference transitive projects difficult - so it's hard to modularize MSBuild. It turns out Coverlet uses Serilog MSBuildSink, but nothing exists for Microsoft.Extensions.Logging. I wrote a dumb one here : https://github.com/fluentmigrator/fluentmigrator/blob/main/src/FluentMigrator.MSBuild/MicrosoftBuildLogger.cs

from @jzabroski in https://github.com/dotnet/msbuild/issues/10756

This is a recurring problem. The SDK Containers have a simple version of an ILogger<->MEL.ILogger mapping, the SBOM targets do as well, and a number of MSBuild integrations I've written in the past for my own tools (Ionide/FSAutoComplete, Ionide/Proj-Info, etc) all have separate implementations.

We should develop and ship a 'blessed' ILogger implementation that interops with MEL.ILogger, and it should be able to handle MSBuild ILogger specific concepts like

rainersigwald commented 1 month ago

Looks like there are several copies of Microsoft.Extensions.Logging DLLs in VS already; I'd want to be careful to make sure that we don't add a "must match" constraint between MSBuild and VS. Otherwise I'd be ok adding this dependency.

baronfel commented 1 month ago

I think we'd only need a dependency on the abstractions assembly, right? That might make navigating the dependency a bit easier.

jzabroski commented 1 month ago

@teo-tsirpanis - Based on our chat yesterday, tagging you here if you wanted to follow/subscribe

teo-tsirpanis commented 1 month ago

MSBuild ILogger specific concepts like

I took a look yesterday at Microsofts.Extensions.Logging and there doesn't seem to be a way to arbitrarily extend log messages, in contrast with Serilog.

baronfel commented 1 month ago

I've seen this handled a few different ways - mostly either by the State features in MEL to encode the code/line/file information, or by specific named formatting parameters on the message format (which can be pulled out of the args). I think this is something of a weakness for MEL and MSBuild logging generally, and we might need something more like Serilog's Message templates to provide some of this context.

jzabroski commented 1 month ago

I mean, yes, I wish Serilog was Microsoft.Extensions.Logging. MEL is meh. 🦺 Hum...Christmas 🎄 is around the corner. 🦺

We use Serilog and provider our own ILog and ILoggingService abstractions where I work and those just call out to Serilog, which calls out to DataDog primarily. ILog = short and sweet type name. ILoggingService = tool to initialize logging, which is required for things like truly modular PowerShell modules written in C#, where you cannot guarantee the logging configuration is loaded on first call to ILog.