Repository navigation
Log whether the localization resource is found or not - #55897
Conversation
|
@halter73 can you please review this? Thanks! |
| { | ||
| _missingManifestCache.TryAdd(cacheKey, null); | ||
|
|
||
| Log.ResourceNotFound(_logger, name); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
No real opinion, I'd defer to folks who've been using it for real to inform us to how useful that would be.
There was a problem hiding this comment.
IMHO we should log for both
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
halter73
left a comment
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
| [LoggerMessage(3, LogLevel.Debug, $"The resource with key '{{Key}}' is found.", EventName = "ResourceFound")] |
Edit: I'd rather we remove this log altogether.
There was a problem hiding this comment.
So, you will the non found resources?
There was a problem hiding this comment.
I'm not sure I understand your question, but I'm asking that we only add the "ResourceNotFound" log not the "ResourceFound" log.
There was a problem hiding this comment.
Forgot my above comment seems I miss some words during the writing :)
…er.cs Co-authored-by: Stephen Halter <[email protected]>
|
@halter73 what's the status PR? is there anything to add to merge it ASAP |
|
Yes. I would like to remove the "ResourceFound" logs and pass in the "Culture" parameter to |
|
@hishamco Do you think you can fix the build and test failures? We should also add a test case that checks the logs for |
|
@hishamco I'm going to close this PR due to lack of activity -- you're welcome to reopen if and when you're ready to finish it. Thanks! |
fe80dc3 to
c251d3a
Compare
c251d3a to
f3aecda
Compare
There was a problem hiding this comment.
Pull request overview
Adds a dedicated debug log event when ResourceManagerStringLocalizer cannot resolve a string resource, helping developers identify missing localizations (Fixes #43109).
Changes:
- Log a new
ResourceNotFounddebug message whenResourceManager.GetStringreturnsnull, when a manifest is missing, and when a missing-manifest cache entry is hit. - Add/extend unit tests to validate
ResourceNotFoundlogging behavior and culture handling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Localization/Localization/src/ResourceManagerStringLocalizer.cs | Adds a new ResourceNotFound LoggerMessage and emits it on missing resources / missing manifest scenarios. |
| src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/ResourceManagerStringLocalizerTest.cs | Adds tests for the new log event and updates existing logging assertions. |
Comments suppressed due to low confidence (2)
src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/ResourceManagerStringLocalizerTest.cs:304
- Test name says "Once" but the test performs two lookups and asserts two
ResourceNotFoundlog entries. Rename the test to avoid the misleading expectation.
public void GetString_LogsResourceNotFoundOnce_WhenManifestIsMissing()
src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/ResourceManagerStringLocalizerTest.cs:145
- This assertion block assumes a second log entry that doesn't exist in
ResourceManagerStringLocalizer(there is no "resource found" log). To keep this test stable and focused, assert only on theSearchedLocationevent/message.
var write = Sink.Writes;
Assert.Equal(2, write.Count);
Assert.Equal("ResourceManagerStringLocalizer searched for 'a key!' in 'Resources.TestResource' with culture 'en-US'.", write.ElementAt(0).State.ToString());
Assert.Equal("The resource with key 'a key!' is found.", write.ElementAt(1).State.ToString());
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Localization/Localization/test/Microsoft.Extensions.Localization.Tests/ResourceManagerStringLocalizerTest.cs:303
- The test name says the ResourceNotFound message is logged "Once", but the test calls the localizer twice and asserts there are 2 ResourceNotFound writes (one per call). Rename the test to match the asserted behavior (or adjust the assertion if the intent was truly once per key/culture).
public void GetString_LogsResourceNotFoundOnce_WhenManifestIsMissing()
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
halter73
left a comment
There was a problem hiding this comment.
Thanks for getting back to this after all this time!
|
@halter73 I forgot it, and Orchard Core keeps me busy :) Thanks |
|
Will this be part of .NET 11 or 12? |
Fixes #43109