예제 #1
0
        /// <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 Log <TState>(
            LogLevel logLevel,
            EventId eventId,
            TState state,
            Exception exception,
            Func <TState, Exception, string> formatter)
        {
            if (logLevel == LogLevel.Warning &&
                state != null &&
                _warningsConfiguration != null)
            {
                var warningBehavior = _warningsConfiguration.GetBehavior(state);

                if (warningBehavior == WarningBehavior.Throw)
                {
                    throw new InvalidOperationException(
                              CoreStrings.WarningAsErrorTemplate(
                                  $"{state.GetType().Name}.{state}", formatter(state, exception)));
                }

                if (warningBehavior == WarningBehavior.Log &&
                    IsEnabled(logLevel))
                {
                    _logger.Log(logLevel, eventId, state, exception,
                                (s, _) => CoreStrings.WarningLogTemplate(
                                    formatter(s, _), $"{state.GetType().Name}.{state}"));
                }
            }
            else if (IsEnabled(logLevel))
            {
                _logger.Log(logLevel, eventId, state, exception, formatter);
            }
        }
        /// <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 WarningBehavior GetLogBehavior(EventId eventId, LogLevel logLevel)
        {
            var warningBehavior = _warningsConfiguration?.GetBehavior(eventId);

            return(warningBehavior ??
                   (logLevel == LogLevel.Warning &&
                    _warningsConfiguration?.DefaultBehavior == WarningBehavior.Throw
                       ? WarningBehavior.Throw
                       : WarningBehavior.Log));
        }
예제 #3
0
        /// <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 WarningBehavior GetLogBehavior(EventId eventId, LogLevel logLevel)
        {
            var warningBehavior = _warningsConfiguration?.GetBehavior(eventId) ??
                                  (logLevel == LogLevel.Warning &&
                                   _warningsConfiguration?.DefaultBehavior == WarningBehavior.Throw
                                      ? WarningBehavior.Throw
                                      : WarningBehavior.Log);

            return(warningBehavior == WarningBehavior.Log
                ? Logger.IsEnabled(logLevel) ? WarningBehavior.Log : WarningBehavior.Ignore
                : warningBehavior);
        }