public void Refresh()
            {
                if (customSource)
                {
                    return;
                }
                if (subordinateConfigurationSource != null)
                {
                    subordinateConfigurationSource.SourceChanged -= compositeConfigurationSource_ConfigurationSourceChanged;
                    subordinateConfigurationSource.Dispose();
                }

                subordinateConfigurationSource = compositeConfigurationSource.CreateSubordinateSource(subordinateSourceName, false);
                if (subordinateConfigurationSource != null)
                {
                    this.subordinateConfigurationSource.SourceChanged += compositeConfigurationSource_ConfigurationSourceChanged;
                }
            }
Example #2
0
        public static LogWriter CreateLogWriterFromConfigFile(
            string configFileName)
        {
            if (!string.IsNullOrWhiteSpace(configFileName))
            {
                if (Path.IsPathRooted(configFileName))
                {
                    _logConfigurationFileName = configFileName;
                }
                else
                {
                    var data = AppDomain
                               .CurrentDomain
                               .GetData("APP_CONFIG_FILE");

                    Debug.Assert(data != null);

                    var path = Path.GetDirectoryName(data.ToString());

                    configFileName            = Path.Combine(path, configFileName);
                    _logConfigurationFileName = !string.IsNullOrWhiteSpace(configFileName) && File.Exists(configFileName)
                                                            ? configFileName
                                                            : null;
                }
            }

            try
            {
                // if the file name is null or empty or does not exists - go for the app.config
                var logConfigSource = _logConfigurationFileName == null
                                                    ? (IConfigurationSource) new SystemConfigurationSource()
                                                    : (IConfigurationSource) new FileConfigurationSource(_logConfigurationFileName);
                var logger = new LogWriterFactory(logConfigSource).Create();

                if (_logConfiguration != null)
                {
                    _logConfiguration.SourceChanged -= (o, e) => Facility.FacilitiesRegistrar.RefreshLogger(
                        CreateLogWriterFromConfigFile(_logConfigurationFileName));
                    _logConfiguration.Dispose();
                }

                _logConfiguration = logConfigSource;
                _logConfiguration.SourceChanged += (o, e) => Facility.FacilitiesRegistrar.RefreshLogger(
                    CreateLogWriterFromConfigFile(_logConfigurationFileName));
                return(logger);
            }
            catch (Exception x)
            {
                if (_logConfiguration != null)
                {
                    _logConfiguration.Dispose();
                }

                // wrap and throw
                throw new ConfigurationErrorsException(
                          string.Format(
                              "There was an error loading the configuration from {0}: {1}",
                              configFileName.IsNullOrWhiteSpace() ? "the configuration file" : configFileName,
                              x.Message),
                          x);
            }
        }
Example #3
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     _config.Dispose();
 }