From 42deab20754a8eea7917bb91c4339175ca1a8a38 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Tue, 27 Feb 2018 16:49:25 -0800 Subject: [PATCH] Make warning as error exception more helpful Issue #9178 --- .../Properties/OracleStrings.Designer.cs | 13 ++++ .../DataAnnotationOracleTest.cs | 3 +- .../Properties/InMemoryStrings.Designer.cs | 2 + .../Query/QueryNoClientEvalTestBase.cs | 45 ++++++++----- .../Query/WarningsTestBase.cs | 12 ++-- .../Properties/RelationalStrings.Designer.cs | 34 ++++++++++ .../LazyLoadProxyTestBase.cs | 12 ++-- .../Properties/SqlServerStrings.Designer.cs | 15 +++++ .../Properties/SqliteStrings.Designer.cs | 12 ++++ src/EFCore/Diagnostics/EventDefinition.cs | 18 ++++- src/EFCore/Diagnostics/EventDefinitionBase.cs | 25 ++++++- src/EFCore/Diagnostics/EventDefinition`.cs | 20 +++++- src/EFCore/Diagnostics/EventDefinition``.cs | 20 +++++- src/EFCore/Diagnostics/EventDefinition```.cs | 20 +++++- src/EFCore/Diagnostics/EventDefinition````.cs | 20 +++++- .../Diagnostics/EventDefinition`````.cs | 20 +++++- .../Diagnostics/EventDefinition``````.cs | 20 +++++- .../Diagnostics/FallbackEventDefinition.cs | 20 +++++- src/EFCore/Properties/CoreStrings.Designer.cs | 66 +++++++++++++++++-- src/EFCore/Properties/CoreStrings.resx | 2 +- .../Query/WarningsTest.cs | 18 +++-- .../InMemoryTransactionManagerTest.cs | 3 +- .../LazyLoadingProxyTests.cs | 3 +- .../DataAnnotationSqlServerTest.cs | 3 +- .../ChangeTracking/Internal/OwnedFixupTest.cs | 3 +- tools/Resources.tt | 2 + 26 files changed, 375 insertions(+), 56 deletions(-) diff --git a/samples/OracleProvider/src/OracleProvider/Properties/OracleStrings.Designer.cs b/samples/OracleProvider/src/OracleProvider/Properties/OracleStrings.Designer.cs index b6fcdd4d08b..11ff2f0b8c8 100644 --- a/samples/OracleProvider/src/OracleProvider/Properties/OracleStrings.Designer.cs +++ b/samples/OracleProvider/src/OracleProvider/Properties/OracleStrings.Designer.cs @@ -67,6 +67,7 @@ public static string TransientExceptionDetected = new EventDefinition( OracleEventId.DecimalTypeDefaultWarning, LogLevel.Warning, + "OracleEventId.DecimalTypeDefaultWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.DecimalTypeDefaultWarning, @@ -79,6 +80,7 @@ public static string TransientExceptionDetected = new EventDefinition( OracleEventId.ByteIdentityColumnWarning, LogLevel.Warning, + "OracleEventId.ByteIdentityColumnWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.ByteIdentityColumnWarning, @@ -113,6 +115,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.DefaultSchemaFound, LogLevel.Debug, + "OracleEventId.DefaultSchemaFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.DefaultSchemaFound, @@ -125,6 +128,7 @@ public static string NoUserId = new FallbackEventDefinition( OracleEventId.ColumnFound, LogLevel.Debug, + "OracleEventId.ColumnFound", _resourceManager.GetString("LogFoundColumn")); /// @@ -134,6 +138,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.ForeignKeyFound, LogLevel.Debug, + "OracleEventId.ForeignKeyFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.ForeignKeyFound, @@ -146,6 +151,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.ForeignKeyReferencesMissingPrincipalTableWarning, LogLevel.Warning, + "OracleEventId.ForeignKeyReferencesMissingPrincipalTableWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.ForeignKeyReferencesMissingPrincipalTableWarning, @@ -158,6 +164,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.MissingSchemaWarning, LogLevel.Warning, + "OracleEventId.MissingSchemaWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.MissingSchemaWarning, @@ -170,6 +177,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.MissingTableWarning, LogLevel.Warning, + "OracleEventId.MissingTableWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.MissingTableWarning, @@ -182,6 +190,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.TableFound, LogLevel.Debug, + "OracleEventId.TableFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.TableFound, @@ -194,6 +203,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.IndexFound, LogLevel.Debug, + "OracleEventId.IndexFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.IndexFound, @@ -206,6 +216,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.PrimaryKeyFound, LogLevel.Debug, + "OracleEventId.PrimaryKeyFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.PrimaryKeyFound, @@ -218,6 +229,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.UniqueConstraintFound, LogLevel.Debug, + "OracleEventId.UniqueConstraintFound", LoggerMessage.Define( LogLevel.Debug, OracleEventId.UniqueConstraintFound, @@ -230,6 +242,7 @@ public static string NoUserId = new EventDefinition( OracleEventId.ForeignKeyPrincipalColumnMissingWarning, LogLevel.Warning, + "OracleEventId.ForeignKeyPrincipalColumnMissingWarning", LoggerMessage.Define( LogLevel.Warning, OracleEventId.ForeignKeyPrincipalColumnMissingWarning, diff --git a/samples/OracleProvider/test/OracleProvider.FunctionalTests/DataAnnotationOracleTest.cs b/samples/OracleProvider/test/OracleProvider.FunctionalTests/DataAnnotationOracleTest.cs index 99434c93e87..ba48f719bf7 100644 --- a/samples/OracleProvider/test/OracleProvider.FunctionalTests/DataAnnotationOracleTest.cs +++ b/samples/OracleProvider/test/OracleProvider.FunctionalTests/DataAnnotationOracleTest.cs @@ -40,7 +40,8 @@ public virtual ModelBuilder Default_for_key_string_column_throws() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.ModelValidationKeyDefaultValueWarning, - RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1))), + RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1)), + "RelationalEventId.ModelValidationKeyDefaultValueWarning"), Assert.Throws(() => Validate(modelBuilder)).Message); return modelBuilder; diff --git a/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs b/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs index 6c050e71899..2f4f5678c32 100644 --- a/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs +++ b/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs @@ -25,6 +25,7 @@ public static class InMemoryStrings = new EventDefinition( InMemoryEventId.ChangesSaved, LogLevel.Information, + "InMemoryEventId.ChangesSaved", LoggerMessage.Define( LogLevel.Information, InMemoryEventId.ChangesSaved, @@ -37,6 +38,7 @@ public static class InMemoryStrings = new EventDefinition( InMemoryEventId.TransactionIgnoredWarning, LogLevel.Warning, + "InMemoryEventId.TransactionIgnoredWarning", LoggerMessage.Define( LogLevel.Warning, InMemoryEventId.TransactionIgnoredWarning, diff --git a/src/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs b/src/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs index a54698b6d48..36ee121bb90 100644 --- a/src/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs +++ b/src/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs @@ -28,7 +28,8 @@ public virtual void Throws_when_where() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.Where(c => c.IsLondon).ToList()) .Message); @@ -43,7 +44,8 @@ public virtual void Throws_when_orderby() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.OrderBy(c => c.IsLondon).ToList()).Message); } @@ -57,7 +59,8 @@ public virtual void Throws_when_orderby_multiple() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc, ClientMethod([c]) asc")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc, ClientMethod([c]) asc"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers .OrderBy(c => c.IsLondon) @@ -77,7 +80,8 @@ public virtual void Throws_when_where_subquery_correlated() CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, RelationalStrings.LogClientEvalWarning.GenerateMessage( - "where {from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}")), + "where {from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers .Where( @@ -95,7 +99,8 @@ public virtual void Throws_when_all() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("All([c].IsLondon)")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("All([c].IsLondon)"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.All(c => c.IsLondon)).Message); } @@ -109,7 +114,8 @@ public virtual void Throws_when_from_sql_composed() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers .FromSql(@"select * from ""Customers""") @@ -140,7 +146,8 @@ public virtual void Throws_when_subquery_main_from_clause() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => (from c1 in context.Customers @@ -160,7 +167,8 @@ public virtual void Throws_when_select_many() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("from Int32 i in value(System.Int32[])")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("from Int32 i in value(System.Int32[])"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => (from c1 in context.Customers @@ -184,7 +192,8 @@ public virtual void Throws_when_join() #else "join UInt32 i in __p_0 on [e1].EmployeeID equals [i]" #endif - )), + ), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => (from e1 in context.Employees @@ -212,7 +221,8 @@ public virtual void Throws_when_group_join() #else "join UInt32 i in __p_0 on [e1].EmployeeID equals [i]" #endif - )), + ), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => (from e1 in context.Employees @@ -234,7 +244,8 @@ public virtual void Throws_when_group_by() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("GroupBy([c].CustomerID, [c])")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("GroupBy([c].CustomerID, [c])"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers .GroupBy(c => c.CustomerID) @@ -250,7 +261,8 @@ public virtual void Throws_when_first() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.First(c => c.IsLondon)).Message); } @@ -264,7 +276,8 @@ public virtual void Throws_when_single() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.Single(c => c.IsLondon)).Message); } @@ -278,7 +291,8 @@ public virtual void Throws_when_first_or_default() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.FirstOrDefault(c => c.IsLondon)).Message); } @@ -292,7 +306,8 @@ public virtual void Throws_when_single_or_default() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.SingleOrDefault(c => c.IsLondon)).Message); } diff --git a/src/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs b/src/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs index af83704d601..aa57d7a8f3c 100644 --- a/src/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs +++ b/src/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs @@ -28,7 +28,8 @@ public virtual void Throws_when_warning_as_error() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.Where(c => c.IsLondon).ToList()).Message); } @@ -130,7 +131,8 @@ public virtual void Last_without_order_by_issues_client_eval_warning() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.Last()).Message); } @@ -144,7 +146,8 @@ public virtual void Last_with_order_by_issues_client_eval_warning_in_subquery() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers .Where(c => c.CustomerID == "ALFKI" @@ -160,7 +163,8 @@ public virtual void LastOrDefault_without_order_by_issues_client_eval_warning() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.QueryClientEvaluationWarning, - RelationalStrings.LogClientEvalWarning.GenerateMessage("LastOrDefault()")), + RelationalStrings.LogClientEvalWarning.GenerateMessage("LastOrDefault()"), + "RelationalEventId.QueryClientEvaluationWarning"), Assert.Throws( () => context.Customers.LastOrDefault()).Message); } diff --git a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs index 341f7656566..a697288e451 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs +++ b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs @@ -87,6 +87,7 @@ public static string RelationalNotInUse = new EventDefinition( RelationalEventId.BoolWithDefaultWarning, LogLevel.Warning, + "RelationalEventId.BoolWithDefaultWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.BoolWithDefaultWarning, @@ -117,6 +118,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.ConnectionOpening, LogLevel.Debug, + "RelationalEventId.ConnectionOpening", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ConnectionOpening, @@ -129,6 +131,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.ConnectionOpened, LogLevel.Debug, + "RelationalEventId.ConnectionOpened", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ConnectionOpened, @@ -141,6 +144,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.ConnectionClosing, LogLevel.Debug, + "RelationalEventId.ConnectionClosing", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ConnectionClosing, @@ -153,6 +157,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.ConnectionClosed, LogLevel.Debug, + "RelationalEventId.ConnectionClosed", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ConnectionClosed, @@ -165,6 +170,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.ConnectionError, LogLevel.Error, + "RelationalEventId.ConnectionError", LoggerMessage.Define( LogLevel.Error, RelationalEventId.ConnectionError, @@ -177,6 +183,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionStarted, LogLevel.Debug, + "RelationalEventId.TransactionStarted", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.TransactionStarted, @@ -189,6 +196,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionUsed, LogLevel.Debug, + "RelationalEventId.TransactionUsed", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.TransactionUsed, @@ -201,6 +209,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionCommitted, LogLevel.Debug, + "RelationalEventId.TransactionCommitted", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.TransactionCommitted, @@ -213,6 +222,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionRolledBack, LogLevel.Debug, + "RelationalEventId.TransactionRolledBack", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.TransactionRolledBack, @@ -225,6 +235,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionDisposed, LogLevel.Debug, + "RelationalEventId.TransactionDisposed", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.TransactionDisposed, @@ -237,6 +248,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.TransactionError, LogLevel.Error, + "RelationalEventId.TransactionError", LoggerMessage.Define( LogLevel.Error, RelationalEventId.TransactionError, @@ -249,6 +261,7 @@ public static string TransactionAssociatedWithDifferentConnection = new EventDefinition( RelationalEventId.DataReaderDisposing, LogLevel.Debug, + "RelationalEventId.DataReaderDisposing", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.DataReaderDisposing, @@ -325,6 +338,7 @@ public static string DiscriminatorPropertyNotFound([CanBeNull] object property, = new EventDefinition( RelationalEventId.AmbientTransactionWarning, LogLevel.Warning, + "RelationalEventId.AmbientTransactionWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.AmbientTransactionWarning, @@ -337,6 +351,7 @@ public static string DiscriminatorPropertyNotFound([CanBeNull] object property, = new EventDefinition( RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning, LogLevel.Warning, + "RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning, @@ -349,6 +364,7 @@ public static string DiscriminatorPropertyNotFound([CanBeNull] object property, = new EventDefinition( RelationalEventId.QueryPossibleExceptionWithAggregateOperator, LogLevel.Warning, + "RelationalEventId.QueryPossibleExceptionWithAggregateOperator", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.QueryPossibleExceptionWithAggregateOperator, @@ -367,6 +383,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationGeneratingDownScript, LogLevel.Debug, + "RelationalEventId.MigrationGeneratingDownScript", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.MigrationGeneratingDownScript, @@ -379,6 +396,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationGeneratingUpScript, LogLevel.Debug, + "RelationalEventId.MigrationGeneratingUpScript", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.MigrationGeneratingUpScript, @@ -391,6 +409,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationApplying, LogLevel.Information, + "RelationalEventId.MigrationApplying", LoggerMessage.Define( LogLevel.Information, RelationalEventId.MigrationApplying, @@ -403,6 +422,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationReverting, LogLevel.Information, + "RelationalEventId.MigrationReverting", LoggerMessage.Define( LogLevel.Information, RelationalEventId.MigrationReverting, @@ -415,6 +435,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrateUsingConnection, LogLevel.Debug, + "RelationalEventId.MigrateUsingConnection", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.MigrateUsingConnection, @@ -427,6 +448,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationsNotApplied, LogLevel.Information, + "RelationalEventId.MigrationsNotApplied", LoggerMessage.Define( LogLevel.Information, RelationalEventId.MigrationsNotApplied, @@ -439,6 +461,7 @@ public static string StoredProcedureIncludeNotSupported = new EventDefinition( RelationalEventId.MigrationsNotFound, LogLevel.Debug, + "RelationalEventId.MigrationsNotFound", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.MigrationsNotFound, @@ -475,6 +498,7 @@ public static string IncompatibleTableNoRelationship([CanBeNull] object table, [ = new EventDefinition( RelationalEventId.ModelValidationKeyDefaultValueWarning, LogLevel.Warning, + "RelationalEventId.ModelValidationKeyDefaultValueWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.ModelValidationKeyDefaultValueWarning, @@ -527,6 +551,7 @@ public static string NoDiscriminatorValue([CanBeNull] object entityType) = new EventDefinition( RelationalEventId.QueryClientEvaluationWarning, LogLevel.Warning, + "RelationalEventId.QueryClientEvaluationWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.QueryClientEvaluationWarning, @@ -555,6 +580,7 @@ public static string ParameterNotObjectArray([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.CommandExecuting, LogLevel.Debug, + "RelationalEventId.CommandExecuting", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.CommandExecuting, @@ -567,6 +593,7 @@ public static string ParameterNotObjectArray([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.CommandExecuted, LogLevel.Information, + "RelationalEventId.CommandExecuted", LoggerMessage.Define( LogLevel.Information, RelationalEventId.CommandExecuted, @@ -579,6 +606,7 @@ public static string ParameterNotObjectArray([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.CommandError, LogLevel.Error, + "RelationalEventId.CommandError", LoggerMessage.Define( LogLevel.Error, RelationalEventId.CommandError, @@ -795,6 +823,7 @@ public static string NoElements = new EventDefinition( RelationalEventId.ConnectionError, LogLevel.Debug, + "RelationalEventId.ConnectionError", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ConnectionError, @@ -897,6 +926,7 @@ public static string ExpectedNonNullParameter([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.AmbientTransactionEnlisted, LogLevel.Debug, + "RelationalEventId.AmbientTransactionEnlisted", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.AmbientTransactionEnlisted, @@ -909,6 +939,7 @@ public static string ExpectedNonNullParameter([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.ExplicitTransactionEnlisted, LogLevel.Debug, + "RelationalEventId.ExplicitTransactionEnlisted", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.ExplicitTransactionEnlisted, @@ -921,6 +952,7 @@ public static string ExpectedNonNullParameter([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.BatchSmallerThanMinBatchSize, LogLevel.Debug, + "RelationalEventId.BatchSmallerThanMinBatchSize", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.BatchSmallerThanMinBatchSize, @@ -933,6 +965,7 @@ public static string ExpectedNonNullParameter([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.BatchReadyForExecution, LogLevel.Debug, + "RelationalEventId.BatchReadyForExecution", LoggerMessage.Define( LogLevel.Debug, RelationalEventId.BatchReadyForExecution, @@ -945,6 +978,7 @@ public static string ExpectedNonNullParameter([CanBeNull] object parameter) = new EventDefinition( RelationalEventId.MigrationAttributeMissingWarning, LogLevel.Warning, + "RelationalEventId.MigrationAttributeMissingWarning", LoggerMessage.Define( LogLevel.Warning, RelationalEventId.MigrationAttributeMissingWarning, diff --git a/src/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs b/src/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs index 697db96314a..1d3ae439fff 100644 --- a/src/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs +++ b/src/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs @@ -56,7 +56,8 @@ public virtual void Lazy_load_collection(EntityState state, bool useAttach, bool Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Children", "ParentProxy")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Children", "ParentProxy"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => parent.Children).Message); } @@ -123,7 +124,8 @@ public virtual void Lazy_load_many_to_one_reference_to_principal(EntityState sta Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Parent", "ChildProxy")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Parent", "ChildProxy"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => child.Parent).Message); } @@ -192,7 +194,8 @@ public virtual void Lazy_load_one_to_one_reference_to_principal(EntityState stat Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Parent", "SingleProxy")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Parent", "SingleProxy"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => single.Parent).Message); } @@ -261,7 +264,8 @@ public virtual void Lazy_load_one_to_one_reference_to_dependent(EntityState stat Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Single", "ParentProxy")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Single", "ParentProxy"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => parent.Single).Message); } diff --git a/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs b/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs index ee622ed3c19..5a425fca622 100644 --- a/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs +++ b/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs @@ -81,6 +81,7 @@ public static string TransientExceptionDetected = new EventDefinition( SqlServerEventId.DecimalTypeDefaultWarning, LogLevel.Warning, + "SqlServerEventId.DecimalTypeDefaultWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.DecimalTypeDefaultWarning, @@ -93,6 +94,7 @@ public static string TransientExceptionDetected = new EventDefinition( SqlServerEventId.ByteIdentityColumnWarning, LogLevel.Warning, + "SqlServerEventId.ByteIdentityColumnWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.ByteIdentityColumnWarning, @@ -129,6 +131,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.DefaultSchemaFound, LogLevel.Debug, + "SqlServerEventId.DefaultSchemaFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.DefaultSchemaFound, @@ -141,6 +144,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.TypeAliasFound, LogLevel.Debug, + "SqlServerEventId.TypeAliasFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.TypeAliasFound, @@ -153,6 +157,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new FallbackEventDefinition( SqlServerEventId.ColumnFound, LogLevel.Debug, + "SqlServerEventId.ColumnFound", _resourceManager.GetString("LogFoundColumn")); /// @@ -162,6 +167,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.ForeignKeyFound, LogLevel.Debug, + "SqlServerEventId.ForeignKeyFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.ForeignKeyFound, @@ -174,6 +180,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.ForeignKeyReferencesMissingPrincipalTableWarning, LogLevel.Warning, + "SqlServerEventId.ForeignKeyReferencesMissingPrincipalTableWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.ForeignKeyReferencesMissingPrincipalTableWarning, @@ -186,6 +193,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.MissingSchemaWarning, LogLevel.Warning, + "SqlServerEventId.MissingSchemaWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.MissingSchemaWarning, @@ -198,6 +206,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.MissingTableWarning, LogLevel.Warning, + "SqlServerEventId.MissingTableWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.MissingTableWarning, @@ -210,6 +219,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new FallbackEventDefinition( SqlServerEventId.SequenceFound, LogLevel.Debug, + "SqlServerEventId.SequenceFound", _resourceManager.GetString("LogFoundSequence")); /// @@ -219,6 +229,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object = new EventDefinition( SqlServerEventId.TableFound, LogLevel.Debug, + "SqlServerEventId.TableFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.TableFound, @@ -245,6 +256,7 @@ public static string DuplicateColumnNameValueGenerationStrategyMismatch([CanBeNu = new EventDefinition( SqlServerEventId.IndexFound, LogLevel.Debug, + "SqlServerEventId.IndexFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.IndexFound, @@ -257,6 +269,7 @@ public static string DuplicateColumnNameValueGenerationStrategyMismatch([CanBeNu = new EventDefinition( SqlServerEventId.PrimaryKeyFound, LogLevel.Debug, + "SqlServerEventId.PrimaryKeyFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.PrimaryKeyFound, @@ -269,6 +282,7 @@ public static string DuplicateColumnNameValueGenerationStrategyMismatch([CanBeNu = new EventDefinition( SqlServerEventId.UniqueConstraintFound, LogLevel.Debug, + "SqlServerEventId.UniqueConstraintFound", LoggerMessage.Define( LogLevel.Debug, SqlServerEventId.UniqueConstraintFound, @@ -281,6 +295,7 @@ public static string DuplicateColumnNameValueGenerationStrategyMismatch([CanBeNu = new EventDefinition( SqlServerEventId.ForeignKeyPrincipalColumnMissingWarning, LogLevel.Warning, + "SqlServerEventId.ForeignKeyPrincipalColumnMissingWarning", LoggerMessage.Define( LogLevel.Warning, SqlServerEventId.ForeignKeyPrincipalColumnMissingWarning, diff --git a/src/EFCore.Sqlite.Core/Properties/SqliteStrings.Designer.cs b/src/EFCore.Sqlite.Core/Properties/SqliteStrings.Designer.cs index b100049f8c6..e4b74017ca1 100644 --- a/src/EFCore.Sqlite.Core/Properties/SqliteStrings.Designer.cs +++ b/src/EFCore.Sqlite.Core/Properties/SqliteStrings.Designer.cs @@ -39,6 +39,7 @@ public static string MigrationScriptGenerationNotSupported = new EventDefinition( SqliteEventId.SchemaConfiguredWarning, LogLevel.Warning, + "SqliteEventId.SchemaConfiguredWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.SchemaConfiguredWarning, @@ -51,6 +52,7 @@ public static string MigrationScriptGenerationNotSupported = new EventDefinition( SqliteEventId.SequenceConfiguredWarning, LogLevel.Warning, + "SqliteEventId.SequenceConfiguredWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.SequenceConfiguredWarning, @@ -69,6 +71,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.SchemasNotSupportedWarning, LogLevel.Warning, + "SqliteEventId.SchemasNotSupportedWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.SchemasNotSupportedWarning, @@ -81,6 +84,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.ColumnFound, LogLevel.Debug, + "SqliteEventId.ColumnFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.ColumnFound, @@ -93,6 +97,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.ForeignKeyFound, LogLevel.Debug, + "SqliteEventId.ForeignKeyFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.ForeignKeyFound, @@ -105,6 +110,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.ForeignKeyReferencesMissingTableWarning, LogLevel.Warning, + "SqliteEventId.ForeignKeyReferencesMissingTableWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.ForeignKeyReferencesMissingTableWarning, @@ -117,6 +123,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.TableFound, LogLevel.Debug, + "SqliteEventId.TableFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.TableFound, @@ -129,6 +136,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.MissingTableWarning, LogLevel.Warning, + "SqliteEventId.MissingTableWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.MissingTableWarning, @@ -141,6 +149,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.ForeignKeyPrincipalColumnMissingWarning, LogLevel.Warning, + "SqliteEventId.ForeignKeyPrincipalColumnMissingWarning", LoggerMessage.Define( LogLevel.Warning, SqliteEventId.ForeignKeyPrincipalColumnMissingWarning, @@ -153,6 +162,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.IndexFound, LogLevel.Debug, + "SqliteEventId.IndexFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.IndexFound, @@ -165,6 +175,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.PrimaryKeyFound, LogLevel.Debug, + "SqliteEventId.PrimaryKeyFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.PrimaryKeyFound, @@ -177,6 +188,7 @@ public static string SequencesNotSupported = new EventDefinition( SqliteEventId.UniqueConstraintFound, LogLevel.Debug, + "SqliteEventId.UniqueConstraintFound", LoggerMessage.Define( LogLevel.Debug, SqliteEventId.UniqueConstraintFound, diff --git a/src/EFCore/Diagnostics/EventDefinition.cs b/src/EFCore/Diagnostics/EventDefinition.cs index 0b741199d81..e3d0c947aed 100644 --- a/src/EFCore/Diagnostics/EventDefinition.cs +++ b/src/EFCore/Diagnostics/EventDefinition.cs @@ -26,7 +26,23 @@ public class EventDefinition : EventDefinitionBase EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinitionBase.cs b/src/EFCore/Diagnostics/EventDefinitionBase.cs index 91e5e6de11e..54452ab4f75 100644 --- a/src/EFCore/Diagnostics/EventDefinitionBase.cs +++ b/src/EFCore/Diagnostics/EventDefinitionBase.cs @@ -18,11 +18,23 @@ public abstract class EventDefinitionBase /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. protected EventDefinitionBase(EventId eventId, LogLevel level) + : this(eventId, level, null) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + protected EventDefinitionBase(EventId eventId, LogLevel level, [CanBeNull] string eventIdCode) { EventId = eventId; Level = level; + EventIdCode = eventIdCode; } /// @@ -35,12 +47,21 @@ protected EventDefinitionBase(EventId eventId, LogLevel level) /// public virtual LogLevel Level { [DebuggerStepThrough] get; } + /// + /// A string representing the code that should be passed to ConfigureWanings to suppress this event as an error. + /// + public virtual string EventIdCode { get; } + /// /// Returns a warning-as-error exception wrapping the given message for this event. /// /// The message to wrap. protected virtual Exception WarningAsError([NotNull] string message) - => new InvalidOperationException(CoreStrings.WarningAsErrorTemplate(EventId.ToString(), message)); + => new InvalidOperationException( + CoreStrings.WarningAsErrorTemplate( + EventId.ToString(), + message, + EventIdCode ?? EventId.Id.ToString())); /// /// Gets the log behavior for this event. This determines whether it should be logged, thrown as an exception or ignored. diff --git a/src/EFCore/Diagnostics/EventDefinition`.cs b/src/EFCore/Diagnostics/EventDefinition`.cs index 8dc44d9ecb9..9f2e1cd87b6 100644 --- a/src/EFCore/Diagnostics/EventDefinition`.cs +++ b/src/EFCore/Diagnostics/EventDefinition`.cs @@ -20,13 +20,29 @@ public class EventDefinition : EventDefinitionBase /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A cached delegate for logging the event. + /// A string representing the code that should be passed to ConfigureWanings. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinition``.cs b/src/EFCore/Diagnostics/EventDefinition``.cs index 40b56bda9b0..2e813334c4c 100644 --- a/src/EFCore/Diagnostics/EventDefinition``.cs +++ b/src/EFCore/Diagnostics/EventDefinition``.cs @@ -20,13 +20,29 @@ public class EventDefinition : EventDefinitionBase /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinition```.cs b/src/EFCore/Diagnostics/EventDefinition```.cs index a11f0090273..239a477d060 100644 --- a/src/EFCore/Diagnostics/EventDefinition```.cs +++ b/src/EFCore/Diagnostics/EventDefinition```.cs @@ -20,13 +20,29 @@ public class EventDefinition : EventDefinitionBase /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinition````.cs b/src/EFCore/Diagnostics/EventDefinition````.cs index b4c948b00ec..dbe1906fb2e 100644 --- a/src/EFCore/Diagnostics/EventDefinition````.cs +++ b/src/EFCore/Diagnostics/EventDefinition````.cs @@ -20,13 +20,29 @@ public class EventDefinition : EventDefiniti /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinition`````.cs b/src/EFCore/Diagnostics/EventDefinition`````.cs index 31030616c80..59917e40e3f 100644 --- a/src/EFCore/Diagnostics/EventDefinition`````.cs +++ b/src/EFCore/Diagnostics/EventDefinition`````.cs @@ -20,13 +20,29 @@ public class EventDefinition : Even /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/EventDefinition``````.cs b/src/EFCore/Diagnostics/EventDefinition``````.cs index e1a92872a3d..5399a7c8bc1 100644 --- a/src/EFCore/Diagnostics/EventDefinition``````.cs +++ b/src/EFCore/Diagnostics/EventDefinition``````.cs @@ -20,13 +20,29 @@ public class EventDefinition /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// A cached delegate for logging the event. public EventDefinition( EventId eventId, LogLevel level, [NotNull] Action logAction) - : base(eventId, level) + : this(eventId, level, null, logAction) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// A cached delegate for logging the event. + public EventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] Action logAction) + : base(eventId, level, eventIdCode) { Check.NotNull(logAction, nameof(logAction)); diff --git a/src/EFCore/Diagnostics/FallbackEventDefinition.cs b/src/EFCore/Diagnostics/FallbackEventDefinition.cs index ec0d37772a9..e44cc22f7d9 100644 --- a/src/EFCore/Diagnostics/FallbackEventDefinition.cs +++ b/src/EFCore/Diagnostics/FallbackEventDefinition.cs @@ -18,13 +18,29 @@ public class FallbackEventDefinition : EventDefinitionBase /// Creates an event definition instance. /// /// The . - /// The at which the event will be logged. + /// The at which the event will be logged. /// The parameterized message definition. public FallbackEventDefinition( EventId eventId, LogLevel level, [NotNull] string messageFormat) - : base(eventId, level) + : this(eventId, level, null, messageFormat) + { + } + + /// + /// Creates an event definition instance. + /// + /// The . + /// The at which the event will be logged. + /// A string representing the code that should be passed to ConfigureWanings. + /// The parameterized message definition. + public FallbackEventDefinition( + EventId eventId, + LogLevel level, + [CanBeNull] string eventIdCode, + [NotNull] string messageFormat) + : base(eventId, level, eventIdCode) { Check.NotEmpty(messageFormat, nameof(messageFormat)); diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 5aaa557f261..c442aa7e62a 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -407,6 +407,7 @@ public static string SingletonOptionChanged([CanBeNull] object optionCall, [CanB = new EventDefinition( CoreEventId.ServiceProviderCreated, LogLevel.Debug, + "CoreEventId.ServiceProviderCreated", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ServiceProviderCreated, @@ -419,6 +420,7 @@ public static string SingletonOptionChanged([CanBeNull] object optionCall, [CanB = new EventDefinition( CoreEventId.ManyServiceProvidersCreatedWarning, LogLevel.Warning, + "CoreEventId.ManyServiceProvidersCreatedWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.ManyServiceProvidersCreatedWarning, @@ -431,6 +433,7 @@ public static string SingletonOptionChanged([CanBeNull] object optionCall, [CanB = new EventDefinition( CoreEventId.ContextInitialized, LogLevel.Information, + "CoreEventId.ContextInitialized", LoggerMessage.Define( LogLevel.Information, CoreEventId.ContextInitialized, @@ -507,6 +510,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.QueryIterationFailed, LogLevel.Error, + "CoreEventId.QueryIterationFailed", LoggerMessage.Define( LogLevel.Error, CoreEventId.QueryIterationFailed, @@ -519,6 +523,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.SaveChangesFailed, LogLevel.Error, + "CoreEventId.SaveChangesFailed", LoggerMessage.Define( LogLevel.Error, CoreEventId.SaveChangesFailed, @@ -531,6 +536,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.DetectChangesStarting, LogLevel.Debug, + "CoreEventId.DetectChangesStarting", LoggerMessage.Define( LogLevel.Debug, CoreEventId.DetectChangesStarting, @@ -543,6 +549,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.DetectChangesCompleted, LogLevel.Debug, + "CoreEventId.DetectChangesCompleted", LoggerMessage.Define( LogLevel.Debug, CoreEventId.DetectChangesCompleted, @@ -555,6 +562,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.PropertyChangeDetected, LogLevel.Debug, + "CoreEventId.PropertyChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.PropertyChangeDetected, @@ -567,6 +575,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.PropertyChangeDetected, LogLevel.Debug, + "CoreEventId.PropertyChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.PropertyChangeDetected, @@ -579,6 +588,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ForeignKeyChangeDetected, LogLevel.Debug, + "CoreEventId.ForeignKeyChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ForeignKeyChangeDetected, @@ -591,6 +601,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ForeignKeyChangeDetected, LogLevel.Debug, + "CoreEventId.ForeignKeyChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ForeignKeyChangeDetected, @@ -603,6 +614,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CollectionChangeDetected, LogLevel.Debug, + "CoreEventId.CollectionChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CollectionChangeDetected, @@ -615,6 +627,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CollectionChangeDetected, LogLevel.Debug, + "CoreEventId.CollectionChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CollectionChangeDetected, @@ -627,6 +640,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ReferenceChangeDetected, LogLevel.Debug, + "CoreEventId.ReferenceChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ReferenceChangeDetected, @@ -639,6 +653,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ReferenceChangeDetected, LogLevel.Debug, + "CoreEventId.ReferenceChangeDetected", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ReferenceChangeDetected, @@ -651,6 +666,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CascadeDelete, LogLevel.Debug, + "CoreEventId.CascadeDelete", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CascadeDelete, @@ -663,6 +679,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CascadeDelete, LogLevel.Debug, + "CoreEventId.CascadeDelete", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CascadeDelete, @@ -675,6 +692,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CascadeDeleteOrphan, LogLevel.Debug, + "CoreEventId.CascadeDeleteOrphan", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CascadeDeleteOrphan, @@ -687,6 +705,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.CascadeDeleteOrphan, LogLevel.Debug, + "CoreEventId.CascadeDeleteOrphan", LoggerMessage.Define( LogLevel.Debug, CoreEventId.CascadeDeleteOrphan, @@ -699,6 +718,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.StartedTracking, LogLevel.Debug, + "CoreEventId.StartedTracking", LoggerMessage.Define( LogLevel.Debug, CoreEventId.StartedTracking, @@ -711,6 +731,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.StartedTracking, LogLevel.Debug, + "CoreEventId.StartedTracking", LoggerMessage.Define( LogLevel.Debug, CoreEventId.StartedTracking, @@ -723,6 +744,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.StateChanged, LogLevel.Debug, + "CoreEventId.StateChanged", LoggerMessage.Define( LogLevel.Debug, CoreEventId.StateChanged, @@ -735,6 +757,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.StateChanged, LogLevel.Debug, + "CoreEventId.StateChanged", LoggerMessage.Define( LogLevel.Debug, CoreEventId.StateChanged, @@ -747,6 +770,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ValueGenerated, LogLevel.Debug, + "CoreEventId.ValueGenerated", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ValueGenerated, @@ -759,6 +783,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ValueGenerated, LogLevel.Debug, + "CoreEventId.ValueGenerated", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ValueGenerated, @@ -771,6 +796,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ValueGenerated, LogLevel.Debug, + "CoreEventId.ValueGenerated", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ValueGenerated, @@ -783,6 +809,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ValueGenerated, LogLevel.Debug, + "CoreEventId.ValueGenerated", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ValueGenerated, @@ -795,6 +822,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.SaveChangesStarting, LogLevel.Debug, + "CoreEventId.SaveChangesStarting", LoggerMessage.Define( LogLevel.Debug, CoreEventId.SaveChangesStarting, @@ -807,6 +835,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.SaveChangesCompleted, LogLevel.Debug, + "CoreEventId.SaveChangesCompleted", LoggerMessage.Define( LogLevel.Debug, CoreEventId.SaveChangesCompleted, @@ -819,6 +848,7 @@ public static string TempValuePersists([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.ContextDisposed, LogLevel.Debug, + "CoreEventId.ContextDisposed", LoggerMessage.Define( LogLevel.Debug, CoreEventId.ContextDisposed, @@ -1093,6 +1123,7 @@ public static string IncludeBadNavigation([CanBeNull] object property, [CanBeNul = new EventDefinition( CoreEventId.QueryModelCompiling, LogLevel.Debug, + "CoreEventId.QueryModelCompiling", LoggerMessage.Define( LogLevel.Debug, CoreEventId.QueryModelCompiling, @@ -1105,6 +1136,7 @@ public static string IncludeBadNavigation([CanBeNull] object property, [CanBeNul = new EventDefinition( CoreEventId.QueryModelOptimized, LogLevel.Debug, + "CoreEventId.QueryModelOptimized", LoggerMessage.Define( LogLevel.Debug, CoreEventId.QueryModelOptimized, @@ -1117,6 +1149,7 @@ public static string IncludeBadNavigation([CanBeNull] object property, [CanBeNul = new EventDefinition( CoreEventId.NavigationIncluded, LogLevel.Debug, + "CoreEventId.NavigationIncluded", LoggerMessage.Define( LogLevel.Debug, CoreEventId.NavigationIncluded, @@ -1129,6 +1162,7 @@ public static string IncludeBadNavigation([CanBeNull] object property, [CanBeNul = new EventDefinition( CoreEventId.QueryExecutionPlanned, LogLevel.Debug, + "CoreEventId.QueryExecutionPlanned", LoggerMessage.Define( LogLevel.Debug, CoreEventId.QueryExecutionPlanned, @@ -1615,6 +1649,7 @@ public static string InvalidAlternateKeyValue([CanBeNull] object entityType, [Ca = new EventDefinition( CoreEventId.SensitiveDataLoggingEnabledWarning, LogLevel.Warning, + "CoreEventId.SensitiveDataLoggingEnabledWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.SensitiveDataLoggingEnabledWarning, @@ -1777,6 +1812,7 @@ public static string NoParameterlessConstructor([CanBeNull] object entityType) = new EventDefinition( CoreEventId.IncludeIgnoredWarning, LogLevel.Warning, + "CoreEventId.IncludeIgnoredWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.IncludeIgnoredWarning, @@ -1791,12 +1827,12 @@ public static string ConflictingRelationshipNavigation([CanBeNull] object newPri newPrincipalEntityType, newPrincipalNavigation, newDependentEntityType, newDependentNavigation, existingPrincipalEntityType, existingPrincipalNavigation, existingDependentEntityType, existingDependentNavigation); /// - /// Warning as error exception for warning '{eventId}': {message} To suppress this Exception use the DbContextOptionsBuilder.ConfigureWarnings API. ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider. + /// Error generated for warning '{eventName}: {message}'. This exception can be suppressed or logged by passing event ID '{eventId}' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'. /// - public static string WarningAsErrorTemplate([CanBeNull] object eventId, [CanBeNull] object message) + public static string WarningAsErrorTemplate([CanBeNull] object eventName, [CanBeNull] object message, [CanBeNull] object eventId) => string.Format( - GetString("WarningAsErrorTemplate", nameof(eventId), nameof(message)), - eventId, message); + GetString("WarningAsErrorTemplate", nameof(eventName), nameof(message), nameof(eventId)), + eventName, message, eventId); /// /// Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. @@ -1897,6 +1933,7 @@ public static string PropertyCalledOnNavigation([CanBeNull] object property, [Ca = new EventDefinition( CoreEventId.RowLimitingOperationWithoutOrderByWarning, LogLevel.Warning, + "CoreEventId.RowLimitingOperationWithoutOrderByWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.RowLimitingOperationWithoutOrderByWarning, @@ -1925,6 +1962,7 @@ public static string PropertyInUseIndex([CanBeNull] object property, [CanBeNull] = new EventDefinition( CoreEventId.FirstWithoutOrderByAndFilterWarning, LogLevel.Warning, + "CoreEventId.FirstWithoutOrderByAndFilterWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.FirstWithoutOrderByAndFilterWarning, @@ -2123,6 +2161,7 @@ public static string IncludeNotSpecifiedDirectlyOnEntityType([CanBeNull] object = new EventDefinition( CoreEventId.PossibleUnintendedCollectionNavigationNullComparisonWarning, LogLevel.Warning, + "CoreEventId.PossibleUnintendedCollectionNavigationNullComparisonWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.PossibleUnintendedCollectionNavigationNullComparisonWarning, @@ -2135,6 +2174,7 @@ public static string IncludeNotSpecifiedDirectlyOnEntityType([CanBeNull] object = new EventDefinition( CoreEventId.PossibleUnintendedReferenceComparisonWarning, LogLevel.Warning, + "CoreEventId.PossibleUnintendedReferenceComparisonWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.PossibleUnintendedReferenceComparisonWarning, @@ -2147,6 +2187,7 @@ public static string IncludeNotSpecifiedDirectlyOnEntityType([CanBeNull] object = new EventDefinition( CoreEventId.DuplicateDependentEntityTypeInstanceWarning, LogLevel.Warning, + "CoreEventId.DuplicateDependentEntityTypeInstanceWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.DuplicateDependentEntityTypeInstanceWarning, @@ -2293,6 +2334,7 @@ public static string TransactionsNotSupported = new EventDefinition( CoreEventId.ShadowPropertyCreated, LogLevel.Information, + "CoreEventId.ShadowPropertyCreated", LoggerMessage.Define( LogLevel.Information, CoreEventId.ShadowPropertyCreated, @@ -2305,6 +2347,7 @@ public static string TransactionsNotSupported = new EventDefinition( CoreEventId.ExecutionStrategyRetrying, LogLevel.Information, + "CoreEventId.ExecutionStrategyRetrying", LoggerMessage.Define( LogLevel.Information, CoreEventId.ExecutionStrategyRetrying, @@ -2317,6 +2360,7 @@ public static string TransactionsNotSupported = new EventDefinition( CoreEventId.NavigationLazyLoading, LogLevel.Information, + "CoreEventId.NavigationLazyLoading", LoggerMessage.Define( LogLevel.Information, CoreEventId.NavigationLazyLoading, @@ -2329,6 +2373,7 @@ public static string TransactionsNotSupported = new EventDefinition( CoreEventId.LazyLoadOnDisposedContextWarning, LogLevel.Warning, + "CoreEventId.LazyLoadOnDisposedContextWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.LazyLoadOnDisposedContextWarning, @@ -2405,6 +2450,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.RedundantIndexRemoved, LogLevel.Information, + "CoreEventId.RedundantIndexRemoved", LoggerMessage.Define( LogLevel.Information, CoreEventId.RedundantIndexRemoved, @@ -2417,6 +2463,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.IncompatibleMatchingForeignKeyProperties, LogLevel.Information, + "CoreEventId.IncompatibleMatchingForeignKeyProperties", LoggerMessage.Define( LogLevel.Information, CoreEventId.IncompatibleMatchingForeignKeyProperties, @@ -2429,6 +2476,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.RequiredAttributeOnDependent, LogLevel.Information, + "CoreEventId.RequiredAttributeOnDependent", LoggerMessage.Define( LogLevel.Information, CoreEventId.RequiredAttributeOnDependent, @@ -2441,6 +2489,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.RequiredAttributeOnBothNavigations, LogLevel.Information, + "CoreEventId.RequiredAttributeOnBothNavigations", LoggerMessage.Define( LogLevel.Information, CoreEventId.RequiredAttributeOnBothNavigations, @@ -2453,6 +2502,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.ForeignKeyAttributesOnBothNavigations, LogLevel.Information, + "CoreEventId.ForeignKeyAttributesOnBothNavigations", LoggerMessage.Define( LogLevel.Information, CoreEventId.ForeignKeyAttributesOnBothNavigations, @@ -2465,6 +2515,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.ForeignKeyAttributesOnBothProperties, LogLevel.Information, + "CoreEventId.ForeignKeyAttributesOnBothProperties", LoggerMessage.Define( LogLevel.Information, CoreEventId.ForeignKeyAttributesOnBothProperties, @@ -2477,6 +2528,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.ConflictingForeignKeyAttributesOnNavigationAndProperty, LogLevel.Information, + "CoreEventId.ConflictingForeignKeyAttributesOnNavigationAndProperty", LoggerMessage.Define( LogLevel.Information, CoreEventId.ConflictingForeignKeyAttributesOnNavigationAndProperty, @@ -2489,6 +2541,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.MultipleInversePropertiesSameTarget, LogLevel.Information, + "CoreEventId.MultipleInversePropertiesSameTarget", LoggerMessage.Define( LogLevel.Information, CoreEventId.MultipleInversePropertiesSameTarget, @@ -2501,6 +2554,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.ConflictingShadowForeignKeysWarning, LogLevel.Warning, + "CoreEventId.ConflictingShadowForeignKeysWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.ConflictingShadowForeignKeysWarning, @@ -2513,6 +2567,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.MultipleNavigationProperties, LogLevel.Information, + "CoreEventId.MultipleNavigationProperties", LoggerMessage.Define( LogLevel.Information, CoreEventId.MultipleNavigationProperties, @@ -2525,6 +2580,7 @@ public static string ErrorNavCannotTargetQueryType([CanBeNull] object type) = new EventDefinition( CoreEventId.MultiplePrimaryKeyCandidates, LogLevel.Information, + "CoreEventId.MultiplePrimaryKeyCandidates", LoggerMessage.Define( LogLevel.Information, CoreEventId.MultiplePrimaryKeyCandidates, @@ -2553,6 +2609,7 @@ public static string InvalidSetTypeWeak([CanBeNull] object typeName) = new EventDefinition( CoreEventId.NonDefiningInverseNavigationWarning, LogLevel.Warning, + "CoreEventId.NonDefiningInverseNavigationWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.NonDefiningInverseNavigationWarning, @@ -2565,6 +2622,7 @@ public static string InvalidSetTypeWeak([CanBeNull] object typeName) = new EventDefinition( CoreEventId.NonOwnershipInverseNavigationWarning, LogLevel.Warning, + "CoreEventId.NonOwnershipInverseNavigationWarning", LoggerMessage.Define( LogLevel.Warning, CoreEventId.NonOwnershipInverseNavigationWarning, diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index fdd0d6c38b8..bb33705e059 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -775,7 +775,7 @@ Cannot create a relationship between '{newPrincipalEntityType}.{newPrincipalNavigation}' and '{newDependentEntityType}.{newDependentNavigation}', because there already is a relationship between '{existingPrincipalEntityType}.{existingPrincipalNavigation}' and '{existingDependentEntityType}.{existingDependentNavigation}'. Navigation properties can only participate in a single relationship. - Warning as error exception for warning '{eventId}': {message} To suppress this Exception use the DbContextOptionsBuilder.ConfigureWarnings API. ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider. + Error generated for warning '{eventName}: {message}'. This exception can be suppressed or logged by passing event ID '{eventId}' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'. Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. diff --git a/test/EFCore.InMemory.FunctionalTests/Query/WarningsTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/WarningsTest.cs index d0767664ff4..26c4dd46257 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/WarningsTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/WarningsTest.cs @@ -30,7 +30,8 @@ var optionsBuilder Assert.Equal( CoreStrings.WarningAsErrorTemplate( InMemoryEventId.TransactionIgnoredWarning, - InMemoryStrings.LogTransactionsNotSupported.GenerateMessage()), + InMemoryStrings.LogTransactionsNotSupported.GenerateMessage(), + "InMemoryEventId.TransactionIgnoredWarning"), Assert.Throws( () => context.Database.BeginTransaction()).Message); } @@ -54,7 +55,8 @@ var optionsBuilder Assert.Equal( CoreStrings.WarningAsErrorTemplate( InMemoryEventId.TransactionIgnoredWarning, - InMemoryStrings.LogTransactionsNotSupported.GenerateMessage()), + InMemoryStrings.LogTransactionsNotSupported.GenerateMessage(), + "InMemoryEventId.TransactionIgnoredWarning"), Assert.Throws( () => context.Database.EnlistTransaction(new CommittableTransaction())).Message); #endif @@ -84,7 +86,8 @@ public void Throws_when_warning_as_error_all() CoreStrings.WarningAsErrorTemplate( CoreEventId.FirstWithoutOrderByAndFilterWarning.ToString(), CoreStrings.LogFirstWithoutOrderByAndFilter.GenerateMessage( - "(from WarningAsErrorEntity _1 in DbSet select [_1]).Firs...")), + "(from WarningAsErrorEntity _1 in DbSet select [_1]).Firs..."), + "CoreEventId.FirstWithoutOrderByAndFilterWarning"), Assert.Throws( () => context.WarningAsErrorEntities.FirstOrDefault()).Message); } @@ -99,7 +102,8 @@ public void Throws_when_warning_as_error_specific() CoreStrings.WarningAsErrorTemplate( CoreEventId.FirstWithoutOrderByAndFilterWarning.ToString(), CoreStrings.LogFirstWithoutOrderByAndFilter.GenerateMessage( - "(from WarningAsErrorEntity _1 in DbSet select [_1]).Firs...")), + "(from WarningAsErrorEntity _1 in DbSet select [_1]).Firs..."), + "CoreEventId.FirstWithoutOrderByAndFilterWarning"), Assert.Throws( () => context.WarningAsErrorEntities.FirstOrDefault()).Message); } @@ -124,7 +128,8 @@ public void Ignored_includes_can_be_configured_to_throw() Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.IncludeIgnoredWarning.ToString(), - CoreStrings.LogIgnoredInclude.GenerateMessage("[e].Nav")), + CoreStrings.LogIgnoredInclude.GenerateMessage("[e].Nav"), + "CoreEventId.IncludeIgnoredWarning"), Assert.Throws( () => context.WarningAsErrorEntities.Include(e => e.Nav).OrderBy(e => e.Id).Select(e => e.Id).ToList()).Message); @@ -156,7 +161,8 @@ public void Throws_by_default_for_lazy_load_with_disposed_context() Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Nav", "WarningAsErrorEntity")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Nav", "WarningAsErrorEntity"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => entity.Nav).Message); } diff --git a/test/EFCore.InMemory.Tests/InMemoryTransactionManagerTest.cs b/test/EFCore.InMemory.Tests/InMemoryTransactionManagerTest.cs index 994413a52e1..aedd05794af 100644 --- a/test/EFCore.InMemory.Tests/InMemoryTransactionManagerTest.cs +++ b/test/EFCore.InMemory.Tests/InMemoryTransactionManagerTest.cs @@ -53,7 +53,8 @@ private static void AssertThrows(Action action) Assert.Equal( CoreStrings.WarningAsErrorTemplate( InMemoryEventId.TransactionIgnoredWarning, - InMemoryStrings.LogTransactionsNotSupported.GenerateMessage()), + InMemoryStrings.LogTransactionsNotSupported.GenerateMessage(), + "InMemoryEventId.TransactionIgnoredWarning"), Assert.Throws(action).Message); } diff --git a/test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs b/test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs index 6207d613b22..66a5b18b1f9 100644 --- a/test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs +++ b/test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs @@ -297,7 +297,8 @@ public void Throws_when_context_is_disposed() Assert.Equal( CoreStrings.WarningAsErrorTemplate( CoreEventId.LazyLoadOnDisposedContextWarning.ToString(), - CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Texts", "PhoneProxy")), + CoreStrings.LogLazyLoadOnDisposedContext.GenerateMessage("Texts", "PhoneProxy"), + "CoreEventId.LazyLoadOnDisposedContextWarning"), Assert.Throws( () => phone.Texts).Message); } diff --git a/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs index 5e75bdb66f6..0012574f078 100644 --- a/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs @@ -41,7 +41,8 @@ public virtual ModelBuilder Default_for_key_string_column_throws() Assert.Equal( CoreStrings.WarningAsErrorTemplate( RelationalEventId.ModelValidationKeyDefaultValueWarning, - RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1))), + RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1)), + "RelationalEventId.ModelValidationKeyDefaultValueWarning"), Assert.Throws(() => Validate(modelBuilder)).Message); return modelBuilder; diff --git a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs index 988241cafb5..daa90297b91 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs @@ -68,7 +68,8 @@ public void Adding_duplicate_owned_entity_throws_by_default() CoreEventId.DuplicateDependentEntityTypeInstanceWarning.ToString(), CoreStrings.LogDuplicateDependentEntityTypeInstance.GenerateMessage( typeof(ParentPN).ShortDisplayName() + "." + nameof(ParentPN.Child2) + "#" + typeof(ChildPN).ShortDisplayName(), - typeof(ParentPN).ShortDisplayName() + "." + nameof(ParentPN.Child1) + "#" + typeof(ChildPN).ShortDisplayName())), + typeof(ParentPN).ShortDisplayName() + "." + nameof(ParentPN.Child1) + "#" + typeof(ChildPN).ShortDisplayName()), + "CoreEventId.DuplicateDependentEntityTypeInstanceWarning"), Assert.Throws(() => context.Entry(principal).Reference(p => p.Child2).TargetEntry).Message); } } diff --git a/tools/Resources.tt b/tools/Resources.tt index 87084406fe6..e84e2266a0f 100644 --- a/tools/Resources.tt +++ b/tools/Resources.tt @@ -64,6 +64,7 @@ namespace <#= model.Namespace #> = new FallbackEventDefinition( <#= resource.EventId #>, LogLevel.<#= resource.Level #>, + "<#= resource.EventId #>", _resourceManager.GetString("<#= resource.Name #>")); <# } @@ -75,6 +76,7 @@ namespace <#= model.Namespace #> = new EventDefinition<#= genericTypes #>( <#= resource.EventId #>, LogLevel.<#= resource.Level #>, + "<#= resource.EventId #>", LoggerMessage.Define<#= genericTypes #>( LogLevel.<#= resource.Level #>, <#= resource.EventId #>,