Skip to content
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

Fix Logging formatting with multiple collections #106213

Closed
wants to merge 1 commit into from

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Aug 9, 2024

Fixes #103338

@tarekgh
Copy link
Member Author

tarekgh commented Aug 9, 2024

@stephentoub @ericstj this is a regression in .NET 8.0. I believe this is meeting the servicing bar and we should port the fix there.

!TryFormatArgumentIfNullOrEnumerable(arg1, ref arg1String) ?
string.Format(CultureInfo.InvariantCulture, _format, arg0, arg1) :
string.Format(CultureInfo.InvariantCulture, _format, arg0String ?? arg0, arg1String ?? arg1);
TryFormatArgumentIfNullOrEnumerable(arg0, ref arg0String) | TryFormatArgumentIfNullOrEnumerable(arg1, ref arg1String) ?
Copy link
Member

@ericstj ericstj Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make TryFormatArgumentIfNullOrEnumerable set stringValue to null when it returns false just to be explicit? I wonder if there is really any reason to check the return value from the Try method at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make TryFormatArgumentIfNullOrEnumerable set stringValue to null when it returns false just to be explicit?

I think it is written this way to avoid forcing initializing the stringValue inside the method. But we initlaize anyway the local variables before calling the Try methods. We can apply your suggestion to be consistent with other Try patterns.

I wonder if there is really any reason to check the return value from the Try method at all.

The only benefit of the checking is to avoid rechecking the args again when calling string.Format. I am not seeing is a big deal eitherway.

@tarekgh
Copy link
Member Author

tarekgh commented Aug 12, 2024

closing this PR and reopened #106283. This one was using my local main branch which was wrong. Please comment on #106283. Thanks!

@tarekgh tarekgh closed this Aug 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Microsoft.Extensions.Logging] Bug: Logging arrays is broken and behaves unreliably
2 participants