Skip to content

Commit

Permalink
Fix passing property and entity type names to ValueGenerated messages
Browse files Browse the repository at this point in the history
Fixes #29517

Parameter-reordering works for exception messages, but doesn't work for log messages.
Also checked there are no other cases of this.
  • Loading branch information
ajcvickers committed Nov 18, 2022
1 parent 8fdc756 commit 035c1fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/EFCore/Diagnostics/CoreLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2785,8 +2785,8 @@ public static void ValueGenerated(
definition.Log(
diagnostics,
internalEntityEntry.Context.GetType().ShortDisplayName(),
property.Name,
internalEntityEntry.EntityType.ShortName());
internalEntityEntry.EntityType.ShortName(),
property.Name);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -2808,8 +2808,8 @@ private static string ValueGenerated(EventDefinitionBase definition, EventData p
var p = (PropertyValueEventData)payload;
return d.GenerateMessage(
p.EntityEntry.Context.GetType().ShortDisplayName(),
p.Property.Name,
p.EntityEntry.Metadata.ShortName());
p.EntityEntry.Metadata.ShortName(),
p.Property.Name);
}

/// <summary>
Expand Down Expand Up @@ -2837,8 +2837,8 @@ public static void ValueGeneratedSensitive(
diagnostics,
internalEntityEntry.Context.GetType().ShortDisplayName(),
value,
property.Name,
internalEntityEntry.EntityType.ShortName());
internalEntityEntry.EntityType.ShortName(),
property.Name);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -2861,8 +2861,8 @@ private static string ValueGeneratedSensitive(EventDefinitionBase definition, Ev
return d.GenerateMessage(
p.EntityEntry.Context.GetType().ShortDisplayName(),
p.Value,
p.Property.Name,
p.EntityEntry.Metadata.ShortName());
p.EntityEntry.Metadata.ShortName(),
p.Property.Name);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 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 @@ -965,19 +965,19 @@
<comment>Debug CoreEventId.StateChanged string string string EntityState EntityState</comment>
</data>
<data name="LogTempValueGenerated" xml:space="preserve">
<value>'{contextType}' generated a temporary value for the property '{2_entityType}.{1_property}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.</value>
<value>'{contextType}' generated a temporary value for the property '{entityType}.{property}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.</value>
<comment>Debug CoreEventId.ValueGenerated string string string</comment>
</data>
<data name="LogTempValueGeneratedSensitive" xml:space="preserve">
<value>'{contextType}' generated temporary value '{keyValue}' for the property '{3_entityType}.{2_property}'.</value>
<value>'{contextType}' generated temporary value '{keyValue}' for the property '{entityType}.{property}'.</value>
<comment>Debug CoreEventId.ValueGenerated string object? string string</comment>
</data>
<data name="LogValueGenerated" xml:space="preserve">
<value>'{contextType}' generated a value for the property '{2_entityType}.{1_property}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.</value>
<value>'{contextType}' generated a value for the property '{entityType}.{property}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.</value>
<comment>Debug CoreEventId.ValueGenerated string string string</comment>
</data>
<data name="LogValueGeneratedSensitive" xml:space="preserve">
<value>'{contextType}' generated value '{keyValue}' for the property '{3_entityType}.{2_property}'.</value>
<value>'{contextType}' generated value '{keyValue}' for the property '{entityType}.{property}'.</value>
<comment>Debug CoreEventId.ValueGenerated string object? string string</comment>
</data>
<data name="ManyToManyOneNav" xml:space="preserve">
Expand Down Expand Up @@ -1496,4 +1496,4 @@
<data name="WrongStateManager" xml:space="preserve">
<value>Cannot start tracking the entry for entity type '{entityType}' because it was created by a different StateManager instance.</value>
</data>
</root>
</root>
8 changes: 4 additions & 4 deletions test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,19 +868,19 @@ public async Task Value_generation_is_logged(bool sensitive, bool async, bool te
Assert.Equal(
sensitive
? CoreResources.LogTempValueGeneratedSensitive(new TestLogger<TestLoggingDefinitions>()).GenerateMessage(
nameof(LikeAZooContextSensitive), 1, nameof(Hat.Id), nameof(Hat))
nameof(LikeAZooContextSensitive), 1, nameof(Hat), nameof(Hat.Id))
: CoreResources.LogTempValueGenerated(new TestLogger<TestLoggingDefinitions>()).GenerateMessage(
nameof(LikeAZooContext), nameof(Hat.Id), nameof(Hat)),
nameof(LikeAZooContext), nameof(Hat), nameof(Hat.Id)),
message);
}
else
{
Assert.Equal(
sensitive
? CoreResources.LogValueGeneratedSensitive(new TestLogger<TestLoggingDefinitions>()).GenerateMessage(
nameof(LikeAZooContextSensitive), 1, nameof(Hat.Id), nameof(Hat))
nameof(LikeAZooContextSensitive), 1, nameof(Hat), nameof(Hat.Id))
: CoreResources.LogValueGenerated(new TestLogger<TestLoggingDefinitions>()).GenerateMessage(
nameof(LikeAZooContext), nameof(Hat.Id), nameof(Hat)),
nameof(LikeAZooContext), nameof(Hat), nameof(Hat.Id)),
message);
}
}
Expand Down

0 comments on commit 035c1fc

Please sign in to comment.