예제 #1
0
        /// <summary>
        /// 列找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="tableName">表名</param>
        /// <param name="columnName">列名</param>
        /// <param name="ordinal">顺序</param>
        /// <param name="dataTypeName">数据类型名</param>
        /// <param name="maxLength">最大长度</param>
        /// <param name="precision">精度</param>
        /// <param name="scale">范围</param>
        /// <param name="nullable">是否可空</param>
        /// <param name="identity">标识符</param>
        /// <param name="defaultValue">默认值</param>
        /// <param name="computedValue">计算值</param>
        public static void ColumnFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string tableName,
            [NotNull] string columnName,
            int ordinal,
            [NotNull] string dataTypeName,
            int maxLength,
            int precision,
            int scale,
            bool nullable,
            bool identity,
            [CanBeNull] string defaultValue,
            [CanBeNull] string computedValue)
        {
            FallbackEventDefinition definition  = OracleStrings.LogFoundColumn;
            WarningBehavior         logBehavior = definition.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                definition.Log(diagnostics, logBehavior, delegate(ILogger l)
                {
                    l.LogDebug(definition.EventId, null, definition.MessageFormat, tableName, columnName, ordinal, dataTypeName, maxLength, precision, scale, nullable, identity, defaultValue, computedValue);
                });
            }
        }
예제 #2
0
        /// <summary>
        ///     Creates an event definition instance.
        /// </summary>
        /// <param name="loggingOptions"> Logging options. </param>
        /// <param name="eventId"> The <see cref="Microsoft.Extensions.Logging.EventId" />. </param>
        /// <param name="level"> The <see cref="LogLevel" /> at which the event will be logged. </param>
        /// <param name="eventIdCode"> A string representing the code that should be passed to <see cref="DbContextOptionsBuilder.ConfigureWarnings"/>. </param>
        protected EventDefinitionBase(
            [NotNull] ILoggingOptions loggingOptions,
            EventId eventId,
            LogLevel level,
            [NotNull] string eventIdCode)
        {
            Check.NotNull(loggingOptions, nameof(loggingOptions));
            Check.NotEmpty(eventIdCode, nameof(eventIdCode));

            EventId     = eventId;
            EventIdCode = eventIdCode;

            var warningsConfiguration = loggingOptions.WarningsConfiguration;

            if (warningsConfiguration != null)
            {
                var levelOverride = warningsConfiguration.GetLevel(eventId);
                if (levelOverride.HasValue)
                {
                    level = levelOverride.Value;
                }

                var behavior = warningsConfiguration.GetBehavior(eventId);
                _warningBehavior = behavior ?? (level == LogLevel.Warning &&
                                                warningsConfiguration.DefaultBehavior == WarningBehavior.Throw
                        ? WarningBehavior.Throw
                        : WarningBehavior.Log);
            }
            else
            {
                _warningBehavior = WarningBehavior.Log;
            }

            Level = level;
        }
        /// <summary>
        ///     Creates a new instance with all options the same as for this instance, but with the given option changed.
        ///     It is unusual to call this method directly. Instead use <see cref="WarningsConfigurationBuilder" />.
        /// </summary>
        /// <param name="warningBehavior"> The option to change. </param>
        /// <returns> A new instance with the option changed. </returns>
        public virtual WarningsConfiguration WithDefaultBehavior(WarningBehavior warningBehavior)
        {
            var clone = Clone();

            clone._defaultBehavior = warningBehavior;

            return(clone);
        }
예제 #4
0
        /// <summary>
        ///     Creates a new instance with all options the same as for this instance, but with the given option changed.
        ///     It is unusual to call this method directly. Instead use <see cref="WarningsConfigurationBuilder" />.
        /// </summary>
        /// <param name="warningBehavior"> The option to change. </param>
        /// <returns> A new instance with the option changed. </returns>
        public virtual WarningsConfiguration WithDefaultBehavior(WarningBehavior warningBehavior)
        {
            var clone = Clone();

            clone._defaultBehavior = warningBehavior;
            _serviceProviderHash   = null;

            return(clone);
        }
        /// <summary>
        ///     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.
        /// </summary>
        public virtual void TryAddExplicit([NotNull] object eventId, WarningBehavior warningBehavior)
        {
            Check.NotNull(eventId, nameof(eventId));

            if (!_explicitBehaviors.ContainsKey(eventId))
            {
                _explicitBehaviors[eventId] = warningBehavior;
            }
        }
        /// <summary>
        ///     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.
        /// </summary>
        public virtual void TryAddExplicit([NotNull] object eventId, WarningBehavior warningBehavior)
        {
            Check.NotNull(eventId, nameof(eventId));

            if (!_explicitBehaviors.ContainsKey(eventId))
            {
                _explicitBehaviors[eventId] = warningBehavior;
            }
        }
        /// <summary>
        ///     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.
        /// </summary>
        public virtual void AddExplicit(
            [NotNull] IEnumerable <object> eventIds, WarningBehavior warningBehavior)
        {
            Check.NotNull(eventIds, nameof(eventIds));

            foreach (var eventId in eventIds)
            {
                _explicitBehaviors[eventId] = warningBehavior;
            }
        }
        /// <summary>
        ///     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.
        /// </summary>
        public virtual void AddExplicit(
            [NotNull] IEnumerable<object> eventIds, WarningBehavior warningBehavior)
        {
            Check.NotNull(eventIds, nameof(eventIds));

            foreach (var eventId in eventIds)
            {
                _explicitBehaviors[eventId] = warningBehavior;
            }
        }
예제 #9
0
        /// <summary>
        /// 表找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="tableName">表名</param>
        public static void TableFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string tableName)
        {
            EventDefinition <string> logFoundTable = OracleStrings.LogFoundTable;
            WarningBehavior          logBehavior   = logFoundTable.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logFoundTable.Log(diagnostics, logBehavior, tableName);
            }
        }
예제 #10
0
        /// <summary>
        /// 缺少方案警告
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="schemaName">方案名</param>
        public static void MissingSchemaWarning(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [CanBeNull] string schemaName)
        {
            EventDefinition <string> logMissingSchema = OracleStrings.LogMissingSchema;
            WarningBehavior          logBehavior      = logMissingSchema.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logMissingSchema.Log(diagnostics, logBehavior, schemaName);
            }
        }
예제 #11
0
        /// <summary>
        /// 主键找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="primaryKeyName">主键名</param>
        /// <param name="tableName">表名</param>
        public static void PrimaryKeyFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string primaryKeyName,
            [NotNull] string tableName)
        {
            EventDefinition <string, string> logFoundPrimaryKey = OracleStrings.LogFoundPrimaryKey;
            WarningBehavior logBehavior = logFoundPrimaryKey.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logFoundPrimaryKey.Log(diagnostics, logBehavior, primaryKeyName, tableName);
            }
        }
예제 #12
0
        /// <summary>
        /// 唯一约束找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="uniqueConstraintName">唯一约束名</param>
        /// <param name="tableName">表名</param>
        public static void UniqueConstraintFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string uniqueConstraintName,
            [NotNull] string tableName)
        {
            EventDefinition <string, string> logFoundUniqueConstraint = OracleStrings.LogFoundUniqueConstraint;
            WarningBehavior logBehavior = logFoundUniqueConstraint.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logFoundUniqueConstraint.Log(diagnostics, logBehavior, uniqueConstraintName, tableName);
            }
        }
        /// <summary>
        ///     Creates a new instance with the given explicit <see cref="WarningBehavior" /> set for
        ///     all given event IDs.
        ///     It is unusual to call this method directly. Instead use <see cref="WarningsConfigurationBuilder" />.
        /// </summary>
        /// <param name="eventIds"> The event IDs for which the behavior should be set. </param>
        /// <param name="warningBehavior"> The behavior to set. </param>
        /// <returns> A new instance with the behaviors set. </returns>
        public virtual WarningsConfiguration WithExplicit(
            [NotNull] IEnumerable <EventId> eventIds, WarningBehavior warningBehavior)
        {
            var clone = Clone();

            clone._explicitBehaviors = new Dictionary <int, WarningBehavior>(_explicitBehaviors);

            foreach (var eventId in eventIds)
            {
                clone._explicitBehaviors[eventId.Id] = warningBehavior;
            }

            return(clone);
        }
예제 #14
0
        /// <summary>
        /// 外键找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="foreignKeyName">外键名</param>
        /// <param name="tableName">表名</param>
        /// <param name="principalTableName">关联的表名</param>
        public static void ForeignKeyReferencesMissingPrincipalTableWarning(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [CanBeNull] string foreignKeyName,
            [CanBeNull] string tableName,
            [CanBeNull] string principalTableName)
        {
            EventDefinition <string, string, string> logPrincipalTableNotInSelectionSet = OracleStrings.LogPrincipalTableNotInSelectionSet;
            WarningBehavior logBehavior = logPrincipalTableNotInSelectionSet.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logPrincipalTableNotInSelectionSet.Log(diagnostics, logBehavior, foreignKeyName, tableName, principalTableName);
            }
        }
예제 #15
0
        /// <summary>
        /// 索引找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="indexName">索引名称</param>
        /// <param name="tableName">表名称</param>
        /// <param name="unique">是否唯一</param>
        public static void IndexFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string indexName,
            [NotNull] string tableName,
            bool unique)
        {
            EventDefinition <string, string, bool> logFoundIndex = OracleStrings.LogFoundIndex;
            WarningBehavior logBehavior = logFoundIndex.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logFoundIndex.Log(diagnostics, logBehavior, indexName, tableName, unique);
            }
        }
예제 #16
0
        /// <summary>
        /// 外键主体列丢失警告
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="foreignKeyName">外键名</param>
        /// <param name="tableName">表名</param>
        /// <param name="principalColumnName">关联的表列名</param>
        /// <param name="principalTableName">关联的表名</param>
        public static void ForeignKeyPrincipalColumnMissingWarning(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string foreignKeyName,
            [NotNull] string tableName,
            [NotNull] string principalColumnName,
            [NotNull] string principalTableName)
        {
            EventDefinition <string, string, string, string> logPrincipalColumnNotFound = OracleStrings.LogPrincipalColumnNotFound;
            WarningBehavior logBehavior = logPrincipalColumnNotFound.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logPrincipalColumnNotFound.Log(diagnostics, logBehavior, foreignKeyName, tableName, principalColumnName, principalTableName);
            }
        }
예제 #17
0
        /// <summary>
        /// 外键找到
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="foreignKeyName">外键名</param>
        /// <param name="tableName">表名</param>
        /// <param name="principalTableName">关联的主表名</param>
        /// <param name="onDeleteAction">删除操作</param>
        public static void ForeignKeyFound(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Scaffolding> diagnostics,
            [NotNull] string foreignKeyName,
            [NotNull] string tableName,
            [NotNull] string principalTableName,
            [NotNull] string onDeleteAction)
        {
            EventDefinition <string, string, string, string> logFoundForeignKey = OracleStrings.LogFoundForeignKey;
            WarningBehavior logBehavior = logFoundForeignKey.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logFoundForeignKey.Log(diagnostics, logBehavior, foreignKeyName, tableName, principalTableName, onDeleteAction);
            }
        }
        /// <summary>
        ///     Logs the event, or throws if the event has been configured to be treated as an error.
        /// </summary>
        /// <typeparam name="TLoggerCategory"> The <see cref="DbLoggerCategory" />. </typeparam>
        /// <param name="logger"> The logger to which the event should be logged. </param>
        /// <param name="warningBehavior"> Whether the event should be logged, thrown as an exception or ignored. </param>
        /// <param name="logAction"> A delegate that will log the message to an <see cref="ILogger" />. </param>
        public virtual void Log <TLoggerCategory>(
            [NotNull] IDiagnosticsLogger <TLoggerCategory> logger,
            WarningBehavior warningBehavior,
            [NotNull] Action <ILogger> logAction)
            where TLoggerCategory : LoggerCategory <TLoggerCategory>, new()
        {
            switch (warningBehavior)
            {
            case WarningBehavior.Log:
                logAction(logger.Logger);
                break;

            case WarningBehavior.Throw:
                throw WarningAsError(GenerateMessage(logAction));
            }
        }
예제 #19
0
        /// <summary>
        ///     Logs the event, or throws if the event has been configured to be treated as an error.
        /// </summary>
        /// <typeparam name="TLoggerCategory"> The <see cref="DbLoggerCategory" />. </typeparam>
        /// <param name="logger"> The logger to which the event should be logged. </param>
        /// <param name="warningBehavior"> Whether the event should be logged, thrown as an exception or ignored. </param>
        /// <param name="exception"> Optional exception associated with the event. </param>
        public virtual void Log <TLoggerCategory>(
            [NotNull] IDiagnosticsLogger <TLoggerCategory> logger,
            WarningBehavior warningBehavior,
            [CanBeNull] Exception exception = null)
            where TLoggerCategory : LoggerCategory <TLoggerCategory>, new()
        {
            switch (warningBehavior)
            {
            case WarningBehavior.Log:
                _logAction(logger.Logger, exception);
                break;

            case WarningBehavior.Throw:
                throw WarningAsError(GenerateMessage(exception));
            }
        }
예제 #20
0
        /// <summary>
        ///     Creates a new instance with the given explicit <see cref="WarningBehavior" /> set for
        ///     all given event IDs.
        ///     It is unusual to call this method directly. Instead use <see cref="WarningsConfigurationBuilder" />.
        /// </summary>
        /// <param name="eventIds"> The event IDs for which the behavior should be set. </param>
        /// <param name="warningBehavior"> The behavior to set. </param>
        /// <returns> A new instance with the behaviors set. </returns>
        public virtual WarningsConfiguration WithExplicit(
            [NotNull] IEnumerable <object> eventIds, WarningBehavior warningBehavior)
        {
            var clone = Clone();

            clone._explicitBehaviors = new Dictionary <object, WarningBehavior>(_explicitBehaviors);

            foreach (var eventId in eventIds)
            {
                clone._explicitBehaviors[eventId] = warningBehavior;
            }

            _serviceProviderHash = null;

            return(clone);
        }
        public virtual void Log <TLoggerCategory>(
            [NotNull] IDiagnosticsLogger <TLoggerCategory> logger,
            WarningBehavior warningBehavior,
            [CanBeNull] TParam1 arg1,
            [CanBeNull] TParam2 arg2)
            where TLoggerCategory : LoggerCategory <TLoggerCategory>, new()
        {
            switch (warningBehavior)
            {
            case WarningBehavior.Log:
                _logAction(logger.Logger, arg1, arg2, null);
                break;

            case WarningBehavior.Throw:
                throw WarningAsError(GenerateMessage(arg1, arg2));
            }
        }
예제 #22
0
        /// <summary>
        /// 字节标识列警告
        /// </summary>
        /// <param name="diagnostics">诊断日志</param>
        /// <param name="property">属性</param>
        public static void ByteIdentityColumnWarning(
            [NotNull] this IDiagnosticsLogger <DbLoggerCategory.Model.Validation> diagnostics,
            [NotNull] IProperty property)
        {
            Check.NotNull(diagnostics, nameof(diagnostics));
            Check.NotNull(property, nameof(property));

            EventDefinition <string, string> logByteIdentityColumn = OracleStrings.LogByteIdentityColumn;
            WarningBehavior logBehavior = logByteIdentityColumn.GetLogBehavior(diagnostics);

            if (logBehavior != WarningBehavior.Ignore)
            {
                logByteIdentityColumn.Log(diagnostics, logBehavior, property.Name, property.DeclaringEntityType.DisplayName());
            }
            if (diagnostics.DiagnosticSource.IsEnabled(logByteIdentityColumn.EventId.Name))
            {
                diagnostics.DiagnosticSource.Write(logByteIdentityColumn.EventId.Name, new PropertyEventData(logByteIdentityColumn, ByteIdentityColumnWarning, property));
            }
        }
예제 #23
0
        /// <summary>
        ///     Logs the event, or throws if the event has been configured to be treated as an error.
        /// </summary>
        /// <typeparam name="TLoggerCategory"> The <see cref="DbLoggerCategory" />. </typeparam>
        /// <param name="logger"> The logger to which the event should be logged. </param>
        /// <param name="warningBehavior"> Whether the event should be logged, thrown as an exception or ignored. </param>
        /// <param name="arg1"> The first message argument. </param>
        /// <param name="arg2"> The second message argument. </param>
        /// <param name="arg3"> The third message argument. </param>
        /// <param name="arg4"> The fourth message argument. </param>
        /// <param name="arg5"> The fifth message argument. </param>
        /// <param name="arg6"> The sixth message argument. </param>
        /// <param name="exception"> Optional exception associated with the event. </param>
        public virtual void Log <TLoggerCategory>(
            [NotNull] IDiagnosticsLogger <TLoggerCategory> logger,
            WarningBehavior warningBehavior,
            [CanBeNull] TParam1 arg1,
            [CanBeNull] TParam2 arg2,
            [CanBeNull] TParam3 arg3,
            [CanBeNull] TParam4 arg4,
            [CanBeNull] TParam5 arg5,
            [CanBeNull] TParam6 arg6,
            [CanBeNull] Exception exception = null)
            where TLoggerCategory : LoggerCategory <TLoggerCategory>, new()
        {
            switch (warningBehavior)
            {
            case WarningBehavior.Log:
                _logAction(logger.Logger, arg1, arg2, arg3, arg4, arg5, arg6, exception);
                break;

            case WarningBehavior.Throw:
                throw WarningAsError(GenerateMessage(arg1, arg2, arg3, arg4, arg5, arg6, exception));
            }
        }
예제 #24
0
 /// <summary>
 ///     <para>
 ///         Sets the default behavior when a warning is generated.
 ///     </para>
 ///     <para>
 ///         Event ID values can be found in <see cref="CoreEventId" /> and
 ///         <see cref="T:Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId" />.
 ///         The database provider being used may also define provider-specific event IDs in a similar class.
 ///     </para>
 /// </summary>
 /// <param name="warningBehavior"> The desired behavior. </param>
 /// <returns> The same builder instance so that multiple calls can be chained. </returns>
 public virtual WarningsConfigurationBuilder Default(WarningBehavior warningBehavior)
 => WithOption(e => e.WithDefaultBehavior(warningBehavior));
        /// <summary>
        ///     Sets the default behavior when a warning is generated.
        /// </summary>
        /// <param name="warningBehavior"> The desired behavior. </param>
        /// <returns> The same builder instance so that multiple calls can be chained. </returns>
        public virtual WarningsConfigurationBuilder Default(WarningBehavior warningBehavior)
        {
            Configuration.DefaultBehavior = warningBehavior;

            return this;
        }
예제 #26
0
 /// <summary>
 ///     Called by a derived class constructor when implementing the <see cref="Clone" /> method.
 /// </summary>
 /// <param name="copyFrom"> The instance that is being cloned. </param>
 protected WarningsConfiguration([NotNull] WarningsConfiguration copyFrom)
 {
     _defaultBehavior   = copyFrom._defaultBehavior;
     _explicitBehaviors = copyFrom._explicitBehaviors;
 }
예제 #27
0
 /// <summary>
 ///     Creates a new instance with the given explicit <see cref="WarningBehavior" /> set for
 ///     the given event ID, but only if no explicit behavior has already been set.
 ///     It is unusual to call this method directly. Instead use <see cref="WarningsConfigurationBuilder" />.
 /// </summary>
 /// <param name="eventId"> The event ID for which the behavior should be set. </param>
 /// <param name="warningBehavior"> The behavior to set. </param>
 /// <returns> A new instance with the behavior set, or this instance if a behavior was already set. </returns>
 public virtual WarningsConfiguration TryWithExplicit([NotNull] object eventId, WarningBehavior warningBehavior)
 => _explicitBehaviors.ContainsKey(eventId)
         ? this
         : WithExplicit(new[] { eventId }, warningBehavior);
예제 #28
0
        /// <summary>
        ///     Sets the default behavior when a warning is generated.
        /// </summary>
        /// <param name="warningBehavior"> The desired behavior. </param>
        /// <returns> The same builder instance so that multiple calls can be chained. </returns>
        public virtual WarningsConfigurationBuilder Default(WarningBehavior warningBehavior)
        {
            Configuration.DefaultBehavior = warningBehavior;

            return(this);
        }