diff --git a/src/EFCore.PG/Internal/NpgsqlLoggerExtensions.cs b/src/EFCore.PG/Internal/NpgsqlLoggerExtensions.cs index 699f6053a3..4b0b6379d1 100644 --- a/src/EFCore.PG/Internal/NpgsqlLoggerExtensions.cs +++ b/src/EFCore.PG/Internal/NpgsqlLoggerExtensions.cs @@ -1,6 +1,7 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Logging; namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal { @@ -12,14 +13,11 @@ public static void MissingSchemaWarning( { var definition = NpgsqlResources.LogMissingSchema(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - schemaName); + definition.Log(diagnostics, schemaName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -29,14 +27,11 @@ public static void MissingTableWarning( { var definition = NpgsqlResources.LogMissingTable(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - tableName); + definition.Log(diagnostics, tableName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -48,40 +43,43 @@ public static void ForeignKeyReferencesMissingPrincipalTableWarning( { var definition = NpgsqlResources.LogPrincipalTableNotInSelectionSet(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - foreignKeyName, tableName, principalTableName); + definition.Log(diagnostics, foreignKeyName, tableName, principalTableName); } // No DiagnosticsSource events because these are purely design-time messages } - /// - /// This API supports the Entity Framework Core infrastructure and is not intended to be used - /// directly from your code. This API may change or be removed in future releases. - /// public static void ColumnFound( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] string tableName, [NotNull] string columnName, [NotNull] string dataTypeName, bool nullable, - [CanBeNull] string defaultValue) + bool identity, + [CanBeNull] string defaultValue, + [CanBeNull] string computedValue) { var definition = NpgsqlResources.LogFoundColumn(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { definition.Log( diagnostics, - warningBehavior, - tableName, columnName, dataTypeName, nullable, defaultValue); + l => l.LogDebug( + definition.EventId, + null, + definition.MessageFormat, + tableName, + columnName, + dataTypeName, + nullable, + identity, + defaultValue, + computedValue)); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -92,14 +90,11 @@ public static void UniqueConstraintFound( { var definition = NpgsqlResources.LogFoundUniqueConstraint(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - uniqueConstraintName, tableName); + definition.Log(diagnostics, uniqueConstraintName, tableName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -109,14 +104,11 @@ public static void EnumColumnSkippedWarning( { var definition = NpgsqlResources.LogEnumColumnSkipped(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - columnName); + definition.Log(diagnostics, columnName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -127,15 +119,11 @@ public static void ExpressionIndexSkippedWarning( { var definition = NpgsqlResources.LogExpressionIndexSkipped(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - indexName, - tableName); + definition.Log(diagnostics, indexName, tableName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -146,15 +134,11 @@ public static void UnsupportedColumnIndexSkippedWarning( { var definition = NpgsqlResources.LogUnsupportedColumnIndexSkipped(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - indexName, - tableName); + definition.Log(diagnostics, indexName, tableName); } + // No DiagnosticsSource events because these are purely design-time messages } @@ -165,15 +149,11 @@ public static void UnsupportedColumnConstraintSkippedWarning( { var definition = NpgsqlResources.LogUnsupportedColumnConstraintSkipped(diagnostics); - var warningBehavior = definition.GetLogBehavior(diagnostics); - if (warningBehavior != WarningBehavior.Ignore) + if (diagnostics.ShouldLog(definition)) { - definition.Log( - diagnostics, - warningBehavior, - indexName, - tableName); + definition.Log(diagnostics, indexName, tableName); } + // No DiagnosticsSource events because these are purely design-time messages } } diff --git a/src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs b/src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs index ea28643b1d..2517ab5e96 100644 --- a/src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs +++ b/src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs @@ -116,27 +116,24 @@ private static readonly ResourceManager _resourceManager = new ResourceManager("Npgsql.EntityFrameworkCore.PostgreSQL.Properties.NpgsqlStrings", typeof(NpgsqlResources).GetTypeInfo().Assembly); /// - /// Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, nullable: {isNullable}, default value: {defaultValue} + /// Found foreign key on table: {tableName}, name: {foreignKeyName}, principal table: {principalTableName}, delete action: {deleteAction}. /// - public static EventDefinition LogFoundColumn([NotNull] IDiagnosticsLogger logger) + public static FallbackEventDefinition LogFoundColumn([NotNull] IDiagnosticsLogger logger) { var definition = ((Diagnostics.Internal.NpgsqlLoggingDefinitions)logger.Definitions).LogFoundColumn; if (definition == null) { definition = LazyInitializer.EnsureInitialized( ref ((Diagnostics.Internal.NpgsqlLoggingDefinitions)logger.Definitions).LogFoundColumn, - () => new EventDefinition( + () => new FallbackEventDefinition( logger.Options, NpgsqlEventId.ColumnFound, LogLevel.Debug, "NpgsqlEventId.ColumnFound", - level => LoggerMessage.Define( - level, - NpgsqlEventId.ColumnFound, - _resourceManager.GetString("LogFoundColumn")))); + _resourceManager.GetString("LogFoundColumn"))); } - return (EventDefinition)definition; + return (FallbackEventDefinition)definition; } /// diff --git a/src/EFCore.PG/Properties/NpgsqlStrings.resx b/src/EFCore.PG/Properties/NpgsqlStrings.resx index da43833bac..9c0dbf482d 100644 --- a/src/EFCore.PG/Properties/NpgsqlStrings.resx +++ b/src/EFCore.PG/Properties/NpgsqlStrings.resx @@ -127,8 +127,8 @@ The property '{property}' on entity type '{entityType}' is configured to use 'SequenceHiLo' value generator, which is only intended for keys. If this was intentional configure an alternate key on the property, otherwise call 'ValueGeneratedNever' or configure store generation for this property. - Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, nullable: {isNullable}, default value: {defaultValue} - Debug NpgsqlEventId.ColumnFound string string string bool string + Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, nullable: {isNullable}, identity: {isIdentity}, default value: {defaultValue}, computed value: {computedValue} + Debug NpgsqlEventId.ColumnFound string string string bool bool string string Found foreign key on table: {tableName}, name: {foreignKeyName}, principal table: {principalTableName}, delete action: {deleteAction}. diff --git a/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs b/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs index 6efc20fa24..e1371bcc5f 100644 --- a/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs +++ b/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs @@ -357,13 +357,6 @@ nspname NOT IN ('pg_catalog', 'information_schema') AND continue; } - logger.ColumnFound( - DisplayName(tableSchema, tableName), - column.Name, - formattedTypeName, - column.IsNullable, - column.DefaultValueSql); - // Default values and PostgreSQL 12 generated columns if (record.GetValueOrDefault("attgenerated") == 's') column.ComputedColumnSql = record.GetValueOrDefault("default"); @@ -437,6 +430,15 @@ nspname NOT IN ('pg_catalog', 'information_schema') AND if (record.GetValueOrDefault("description") is string comment) column.Comment = comment; + logger.ColumnFound( + DisplayName(tableSchema, tableName), + column.Name, + formattedTypeName, + column.IsNullable, + isIdentity, + column.DefaultValueSql, + column.ComputedColumnSql); + table.Columns.Add(column); } } diff --git a/tools/Resources.tt b/tools/Resources.tt index 6f32658f1f..e61ed05a3d 100644 --- a/tools/Resources.tt +++ b/tools/Resources.tt @@ -69,7 +69,7 @@ namespace <#= model.Namespace #> <#= model.AccessModifier #> static class <#= model.Class #> { private static readonly ResourceManager _resourceManager - = new ResourceManager("<#= model.ResourceName #>", typeof(<#= model.Class #>).GetTypeInfo().Assembly); + = new ResourceManager("<#= model.ResourceName #>", typeof(<#= model.Class #>).Assembly); <# foreach (var resource in model.Resources) { @@ -136,7 +136,7 @@ namespace <#= model.Namespace.EndsWith(".Internal") ? model.Namespace : (model.N <#= model.AccessModifier #> static class <#= model.DiagnosticsClass #> { private static readonly ResourceManager _resourceManager - = new ResourceManager("<#= model.ResourceName #>", typeof(<#= model.DiagnosticsClass #>).GetTypeInfo().Assembly); + = new ResourceManager("<#= model.ResourceName #>", typeof(<#= model.DiagnosticsClass #>).Assembly); <# foreach (var resource in model.Resources) {