Ejemplo n.º 1
0
        private void HandleConfigSourceError(IConfigurationSource source, Exception exception,
                                             SourceExceptionHandleResult handleResult)
        {
            handleResult.IsHandled = true;

            if (exception is ConfigurationFileSourceException fileException)
            {
                Log.Error($"Configuration file '{fileException.FileName}' error", exception);
            }
            else
            {
                Log.Error($"Configuration source '{source.GetType().Name}' error", exception);
            }

            if (_haltOnConfigError)
            {
                Environment.Exit(1);
            }
        }
Ejemplo n.º 2
0
        private T InvokeWithExceptionHandling <T>(IConfigurationSource source, Func <IConfigurationSource, T> function)
            where T : class
        {
            try
            {
                return(function(source));
            }
            catch (Exception ex)
            {
                var handleResult = new SourceExceptionHandleResult();

                _onSourceExceptions.ForEach(onSourceException => onSourceException(source, ex, handleResult));

                if (!handleResult.IsHandled)
                {
                    throw;
                }

                return(source.GetDefaultSettingObject() as T);
            }
        }