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

Log whether the localization resource is found or not #55897

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

hishamco
Copy link
Member

Fixes #43109

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 27, 2024
@hishamco hishamco requested a review from halter73 May 27, 2024 03:05
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 27, 2024
@mkArtakMSFT mkArtakMSFT added area-ui-rendering Includes: MVC Views/Pages, Razor Views/Pages and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 28, 2024
@mkArtakMSFT
Copy link
Member

@halter73 can you please review this? Thanks!

}
catch (MissingManifestResourceException)
{
_missingManifestCache.TryAdd(cacheKey, null);

Log.ResourceNotFound(_logger, name);
Copy link
Member

Choose a reason for hiding this comment

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

Should we provide a different log for a missing manifest vs a non-localized resource where the name == value?

@DamianEdwards do you have an opinion on this?

Copy link
Member

Choose a reason for hiding this comment

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

No real opinion, I'd defer to folks who've been using it for real to inform us to how useful that would be.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMHO we should log for both

Copy link
Member

@halter73 halter73 May 31, 2024

Choose a reason for hiding this comment

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

I agree we should log in both cases. I was asking if there should be a different log message for the two places this PR currently calls Log.ResourceNotFound since the resource was not found for slightly different reasons, but I'm fine with using the same message whenever a resource is not found for any reason like the PR does currently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or we could change the log level for missing manifest to trace so in debug the missing resources will be logged which are useful in almost cases

Copy link
Member

Choose a reason for hiding this comment

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

I'd just leave them exactly the same for now. If we were going to change the log level, we'd want to give it a unique event id and log message. Changing the level of a log but nothing else would be confusing.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

Given that the SearchedLocation log exists, I wonder if we need a ResourceFound log. A lack of a ResourceNotFound log should imply that it was found. This would also mean less debug log noise for a fully localized application which seems like a good thing.

[LoggerMessage(2, LogLevel.Debug, $"The resource with key '{{Key}}' is not found.", EventName = "ResourceNotFound")]
public static partial void ResourceNotFound(ILogger logger, string key);

[LoggerMessage(3, LogLevel.Debug, $"The resource with key '{{Key}}' is found.", EventName = "ResourceFound")]
Copy link
Member

@halter73 halter73 May 30, 2024

Choose a reason for hiding this comment

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

Suggested change
[LoggerMessage(3, LogLevel.Debug, $"The resource with key '{{Key}}' is found.", EventName = "ResourceFound")]

Edit: I'd rather we remove this log altogether.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, you will the non found resources?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand your question, but I'm asking that we only add the "ResourceNotFound" log not the "ResourceFound" log.

Copy link
Member Author

Choose a reason for hiding this comment

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

Forgot my above comment seems I miss some words during the writing :)

…er.cs

Co-authored-by: Stephen Halter <halter73@gmail.com>
Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jun 8, 2024
@hishamco
Copy link
Member Author

hishamco commented Jun 8, 2024

@halter73 what's the status PR? is there anything to add to merge it ASAP

@halter73
Copy link
Member

Yes. I would like to remove the "ResourceFound" logs and pass in the "Culture" parameter to Log.ResourceNotFound(_logger, name, keyCulture);. Not doing so is currently causing build errors now that the log message includes {{Culture}} in it.

@halter73
Copy link
Member

halter73 commented Jul 8, 2024

@hishamco Do you think you can fix the build and test failures? We should also add a test case that checks the logs for $"A resource for '{{Key}}' with culture '{{Culture}}' was not found.".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ui-rendering Includes: MVC Views/Pages, Razor Views/Pages community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log a message when ResourceManagerStringLocalizer cannot find a resource
4 participants