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 order of arguments passed to log messages #24525

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/EFCore/Diagnostics/CoreLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public static void InvalidIncludePathError(
var definition = CoreResources.LogInvalidIncludePath(diagnostics);
if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, navigationChain, navigationName);
definition.Log(diagnostics, navigationName, navigationChain);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -692,7 +692,7 @@ private static string InvalidIncludePathError(EventDefinitionBase definition, Ev
var d = (EventDefinition<object, object>)definition;
var p = (InvalidIncludePathEventData)payload;

return d.GenerateMessage(p.NavigationChain, p.NavigationName);
return d.GenerateMessage(p.NavigationName, p.NavigationChain);
}

/// <summary>
Expand Down Expand Up @@ -938,7 +938,7 @@ public static void LazyLoadOnDisposedContextWarning(

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, navigationName, entityType.GetType().ShortDisplayName());
definition.Log(diagnostics, entityType.GetType().ShortDisplayName(), navigationName);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -958,7 +958,7 @@ private static string LazyLoadOnDisposedContextWarning(EventDefinitionBase defin
{
var d = (EventDefinition<string, string>)definition;
var p = (LazyLoadingEventData)payload;
return d.GenerateMessage(p.NavigationPropertyName, p.Entity.GetType().ShortDisplayName());
return d.GenerateMessage(p.Entity.GetType().ShortDisplayName(), p.NavigationPropertyName);
}

/// <summary>
Expand All @@ -978,7 +978,7 @@ public static void NavigationLazyLoading(

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, navigationName, entityType.GetType().ShortDisplayName());
definition.Log(diagnostics, entityType.GetType().ShortDisplayName(), navigationName);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -998,7 +998,7 @@ private static string NavigationLazyLoading(EventDefinitionBase definition, Even
{
var d = (EventDefinition<string, string>)definition;
var p = (LazyLoadingEventData)payload;
return d.GenerateMessage(p.NavigationPropertyName, p.Entity.GetType().ShortDisplayName());
return d.GenerateMessage(p.Entity.GetType().ShortDisplayName(), p.NavigationPropertyName);
}

/// <summary>
Expand Down Expand Up @@ -1081,7 +1081,7 @@ public static void ShadowPropertyCreated(

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
definition.Log(diagnostics, property.DeclaringEntityType.DisplayName(), property.Name);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -1099,7 +1099,7 @@ private static string ShadowPropertyCreated(EventDefinitionBase definition, Even
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(p.Property.Name, p.Property.DeclaringEntityType.DisplayName());
return d.GenerateMessage(p.Property.DeclaringEntityType.DisplayName(), p.Property.Name);
}

/// <summary>
Expand All @@ -1115,7 +1115,7 @@ public static void CollectionWithoutComparer(

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
definition.Log(diagnostics, property.DeclaringEntityType.DisplayName(), property.Name);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -1133,7 +1133,7 @@ private static string CollectionWithoutComparer(EventDefinitionBase definition,
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(p.Property.Name, p.Property.DeclaringEntityType.DisplayName());
return d.GenerateMessage(p.Property.DeclaringEntityType.DisplayName(), p.Property.Name);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
<comment>Debug CoreEventId.CollectionChangeDetected int int string string string</comment>
</data>
<data name="LogCollectionWithoutComparer" xml:space="preserve">
<value>The property '{1_entityType}.{0_property}' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly.</value>
<value>The property '{entityType}.{property}' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly.</value>
<comment>Warning CoreEventId.CollectionWithoutComparer string string</comment>
</data>
<data name="LogConflictingForeignKeyAttributesOnNavigationAndProperty" xml:space="preserve">
Expand Down Expand Up @@ -785,11 +785,11 @@
<comment>Debug CoreEventId.IncompatibleMatchingForeignKeyProperties string string string string</comment>
</data>
<data name="LogInvalidIncludePath" xml:space="preserve">
<value>Unable to find navigation '{1_navigation}' specified in string based include path '{0_navigationChain}'.</value>
<value>Unable to find navigation '{navigation}' specified in string based include path '{navigationChain}'.</value>
<comment>Error CoreEventId.InvalidIncludePathError object object</comment>
</data>
<data name="LogLazyLoadOnDisposedContext" xml:space="preserve">
<value>An attempt was made to lazy-load navigation '{1_entityType}.{0_navigation}' after the associated DbContext was disposed.</value>
<value>An attempt was made to lazy-load navigation '{entityType}.{navigation}' after the associated DbContext was disposed.</value>
<comment>Warning CoreEventId.LazyLoadOnDisposedContextWarning string string</comment>
</data>
<data name="LogManyServiceProvidersCreated" xml:space="preserve">
Expand Down Expand Up @@ -817,7 +817,7 @@
<comment>Error CoreEventId.NavigationBaseIncludeIgnored string</comment>
</data>
<data name="LogNavigationLazyLoading" xml:space="preserve">
<value>The navigation '{1_entityType}.{0_navigation}' is being lazy-loaded.</value>
<value>The navigation '{entityType}.{navigation}' is being lazy-loaded.</value>
<comment>Debug CoreEventId.NavigationLazyLoading string string</comment>
</data>
<data name="LogNonDefiningInverseNavigation" xml:space="preserve">
Expand Down Expand Up @@ -937,7 +937,7 @@
<comment>Debug CoreEventId.ServiceProviderDebugInfo string</comment>
</data>
<data name="LogShadowPropertyCreated" xml:space="preserve">
<value>The property '{1_entityType}.{0_property}' was created in shadow state because there are no eligible CLR members with a matching name.</value>
<value>The property '{entityType}.{property}' was created in shadow state because there are no eligible CLR members with a matching name.</value>
<comment>Debug CoreEventId.ShadowPropertyCreated string string</comment>
</data>
<data name="LogSkipCollectionChangeDetected" xml:space="preserve">
Expand Down
10 changes: 5 additions & 5 deletions test/EFCore.InMemory.FunctionalTests/Query/WarningsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void Throws_by_default_for_lazy_load_with_disposed_context()
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<InMemoryLoggingDefinitions>())
.GenerateMessage("Nav", "WarningAsErrorEntity"),
.GenerateMessage("WarningAsErrorEntity", "Nav"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => entity.Nav).Message);
Expand Down Expand Up @@ -141,7 +141,7 @@ public void Lazy_load_with_disposed_context_can_be_configured_to_log()
l => l.Message
== CoreResources
.LogLazyLoadOnDisposedContext(new TestLogger<InMemoryLoggingDefinitions>())
.GenerateMessage("Nav", "WarningAsErrorEntity"));
.GenerateMessage("WarningAsErrorEntity", "Nav"));

Assert.Equal(LogLevel.Warning, log.Level);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public void Lazy_load_with_disposed_context_can_be_configured_to_log_at_debug_le
l => l.Message
== CoreResources
.LogLazyLoadOnDisposedContext(new TestLogger<InMemoryLoggingDefinitions>())
.GenerateMessage("Nav", "WarningAsErrorEntity"));
.GenerateMessage("WarningAsErrorEntity", "Nav"));

Assert.Equal(LogLevel.Debug, log.Level);
}
Expand Down Expand Up @@ -213,14 +213,14 @@ public void Lazy_loading_is_logged_only_when_actually_loading()

Assert.Contains(
CoreResources.LogNavigationLazyLoading(new TestLogger<InMemoryLoggingDefinitions>())
.GenerateMessage("Nav", "WarningAsErrorEntity"),
.GenerateMessage("WarningAsErrorEntity", "Nav"),
loggerFactory.Log.Select(l => l.Message));

loggerFactory.Clear();
Assert.NotNull(entity.Nav);
Assert.DoesNotContain(
CoreResources.LogNavigationLazyLoading(new TestLogger<InMemoryLoggingDefinitions>())
.GenerateMessage("Nav", "WarningAsErrorEntity"),
.GenerateMessage("WarningAsErrorEntity", "Nav"),
loggerFactory.Log.Select(l => l.Message));
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Throws_when_context_is_disposed()
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Texts", "PhoneProxy"),
.GenerateMessage("PhoneProxy", "Texts"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => phone.Texts).Message);
Expand Down
8 changes: 4 additions & 4 deletions test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public virtual void Lazy_load_collection(EntityState state, bool useAttach, bool
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Children", "MotherProxy"),
.GenerateMessage("MotherProxy", "Children"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => parent.Children).Message);
Expand Down Expand Up @@ -347,7 +347,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal(EntityState sta
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Parent", "ChildProxy"),
.GenerateMessage("ChildProxy", "Parent"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => child.Parent).Message);
Expand Down Expand Up @@ -424,7 +424,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal(EntityState stat
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Parent", "SingleProxy"),
.GenerateMessage("SingleProxy", "Parent"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => single.Parent).Message);
Expand Down Expand Up @@ -501,7 +501,7 @@ public virtual void Lazy_load_one_to_one_reference_to_dependent(EntityState stat
CoreStrings.WarningAsErrorTemplate(
CoreEventId.LazyLoadOnDisposedContextWarning.ToString(),
CoreResources.LogLazyLoadOnDisposedContext(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Single", "MotherProxy"),
.GenerateMessage("MotherProxy", "Single"),
"CoreEventId.LazyLoadOnDisposedContextWarning"),
Assert.Throws<InvalidOperationException>(
() => parent.Single).Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,7 @@ public virtual async Task Include_collection_and_invalid_navigation_using_string

Assert.Contains(
CoreResources.LogInvalidIncludePath(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Reports.Foo", "Foo"), message);
.GenerateMessage("Foo", "Reports.Foo"), message);
}

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override async Task Include_property_after_navigation(bool async)
{
Assert.Contains(
CoreResources.LogInvalidIncludePath(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Customer.CustomerID", "CustomerID"),
.GenerateMessage("CustomerID", "Customer.CustomerID"),
(await Assert.ThrowsAsync<InvalidOperationException>(
() => AssertQuery(
async,
Expand Down
6 changes: 3 additions & 3 deletions test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public virtual void Detects_custom_converter_for_collection_type_without_compare

VerifyWarning(
CoreResources.LogCollectionWithoutComparer(
new TestLogger<TestLoggingDefinitions>()).GenerateMessage("SomeStrings", "WithCollectionConversion"),
new TestLogger<TestLoggingDefinitions>()).GenerateMessage("WithCollectionConversion", "SomeStrings"),
convertedProperty.DeclaringEntityType.Model);
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public virtual void Passes_on_shadow_key_created_explicitly()
((IConventionEntityType)entityType).AddKey(keyProperty);

VerifyWarning(
CoreResources.LogShadowPropertyCreated(new TestLogger<TestLoggingDefinitions>()).GenerateMessage("Key", "A"), model,
CoreResources.LogShadowPropertyCreated(new TestLogger<TestLoggingDefinitions>()).GenerateMessage("A", "Key"), model,
LogLevel.Debug);
}

Expand All @@ -220,7 +220,7 @@ public virtual void Passes_on_shadow_primary_key_created_by_convention_in_depend

VerifyWarning(
CoreResources.LogShadowPropertyCreated(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Key", "A"), (IMutableModel)model, LogLevel.Debug);
.GenerateMessage("A", "Key"), (IMutableModel)model, LogLevel.Debug);
}

[ConditionalFact]
Expand Down