-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add the ability to disable code generation, that overrides default code generators from Microsoft.Extensions.Logging #5476
Comments
@vanbukin Could you, please, try to use the following property? <PropertyGroup>
<DisableMicrosoftExtensionsLoggingSourceGenerator>false</DisableMicrosoftExtensionsLoggingSourceGenerator>
</PropertyGroup> Setting it to |
I checked and it doesn't work.
This happens because the NuGet package contains a |
That sounds like a bug, unless I'm missing something. @RussKie @dariusclay How do you think if we should remove the |
I'm less familiar with the Resilience package. Does it depend on anything in particular from the Telemetry.Abstractions package? I'll need to confirm. The thing is, if redaction or enrichment is required anywhere then ExtendedLogger should be used. |
The other comment here, is that the dotnet/extensions logging generator SHOULD be compatible with the one provided by dotnet/runtime, and thus should not break users when this one is used. If breaks users then it's a bug and we can work to fix the problem instead. |
It means you set it too early. Try setting it in a targets file. |
It would be great if you could provide a simple standalone repro so we could investigate it further. Without a repro we'd be speculating a lot. |
I made a repository that reproduces the problem. |
Uncomment the installation of
Next, I try to fix these errors by setting the
<Project>
<PropertyGroup>
<DisableMicrosoftExtensionsLoggingSourceGenerator>false</DisableMicrosoftExtensionsLoggingSourceGenerator>
</PropertyGroup>
</Project> leads me to the following errors:
<Project>
<PropertyGroup>
...
<DisableMicrosoftExtensionsLoggingSourceGenerator>false</DisableMicrosoftExtensionsLoggingSourceGenerator>
</PropertyGroup>
</Project>
and we get the following error:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
...
<DisableMicrosoftExtensionsLoggingSourceGenerator>false</DisableMicrosoftExtensionsLoggingSourceGenerator>
</PropertyGroup>
</Project> and we get:
<Project>
<Target Name="_Microsoft_Extensions_Telemetry_AbstractionsRemoveAnalyzers" BeforeTargets="ResolveReferences">
<PropertyGroup>
<DisableMicrosoftExtensionsLoggingSourceGenerator>false</DisableMicrosoftExtensionsLoggingSourceGenerator>
</PropertyGroup>
</Target>
</Project> no luck:
|
@vanbukin Thank you for sharing the repro steps. I played with the project and wasn't able to fix the issue too. As @dariusclay mentioned, our source generator should be compatible with the one provided by Microsoft.Extensions.Logging.Abstractions and shouldn't break customers, e.g. triggering warnings or errors. What if we update our source generator not to trigger |
@geeknoid any thoughts on this? |
@iliar-turdushev If the logging behavior does not change, then this also looks like an acceptable option. |
Background and motivation
As a developer, I want to add different policies to my http clients that ensure resilience: retry, bulkhead, timeout, etc.
I am connecting the nuget package
Microsoft.Extensions.Http.Resilience
, which contains all the necessary classes for this.My project includes
treat warnings as errors
, as well as all analyzers.My logging is breaking down.
This happens because the
Microsoft.Extensions.Http.Resilience
package depends on theMicrosoft.Extensions.Resilience
package, which in turn depends onMicrosoft.Extensions.Telemetry.Abstractions
, which contains custom code generation for logging and its own set of analyzers, which also override code generation for logs fromMicrosoft.Extensions.Logging
.As a developer, I want to retries for HTTP clients, please do not touch my logs.
I have the following code in my project that works with the
Microsoft.Extensions.Logging
code generator, which understands the MessageTemplates formatthen my logs are transferred to
Serilog
, which also understands the MessageTemplates format and when writing to sink via the formatter, it decomposes the transferred object into separate properties.And I want it to stay as it is, but instead I get a warning
Due to
treat warnings as errors
, this becomes a compilation error.I could suppress it or implement what is required from me, but the problem is not in the warning as such, but in the fact that instead of the code generator from
Microsoft.Extensions.Logging
, I now use the code generator fromMicrosoft.Extensions.Telemetry.Abstractions
.Therefore, I suggest adding an MSBuild property that allows to disable this logic globally (via Directory.Build.props at the level .sln) or locally (at the level of a single project, in its .csproj file).
API Proposal
MSBuild property that disables the replacement of the log generator from
Microsoft.Extensions.Logging
with the log generator fromMicrosoft.Extensions.Telemetry.Abstractions
API Usage
Set the required value to
true
in the csproj file or in theDirectory.Build.props
Workaround
Directory.Build.targets
Risks
When referencing any NuGet package that has a dependency on
Microsoft.Extensions.Telemetry.Abstractions
, another code generator for logs begins to be used.The text was updated successfully, but these errors were encountered: