static Logger() { try { LoggingSection section = GetConfigurationSection(); LoggingProviderCollection providerCollection = LoadAndInitializeProviderCollection(section); LoggingProviderBase defaultProvider = GetDefaultProvider(section, providerCollection); InitializeFallbackProviders(providerCollection); CompleteInitialization(providerCollection, defaultProvider); CircularReferenceFinder.Validate(providerCollection); Logger.providers = providerCollection; Logger.provider = defaultProvider; } catch (ProviderException pex) { // When a ProviderException or ConfigurationException is thrown, we store those and throw them // when one of the public methods of Logger is called. This way the original exceptions are // thrown and not a TypeInitializeException that wraps the original. InitializationException = pex; } catch (ConfigurationException ceex) { InitializationException = ceex; } }
private static void CompleteInitialization(LoggingProviderCollection providers, LoggingProviderBase defaultProvider) { foreach (LoggingProviderBase provider in providers) { provider.CompleteInitialization(providers, defaultProvider); } }
internal override void CompleteInitialization(LoggingProviderCollection configuredProviders, LoggingProviderBase defaultProvider) { // Finish performing implementation-specific provider initialization here (this is 2nd/last part). // This operation has to be executed here, because during Initialize this list of configured is // providers not yet available. this.InitializeProviders(configuredProviders); this.SetInitialized(true); }
// Throws a ConfigurationErrorsException (descendant of ConfigurationException) on failure. private static LoggingProviderBase GetDefaultProvider(LoggingSection loggingSection, LoggingProviderCollection providerCollection) { LoggingProviderBase defaultProvider = providerCollection[loggingSection.DefaultProvider]; if (defaultProvider == null) { PropertyInformation property = loggingSection.ElementInformation.Properties["defaultProvider"]; throw new ConfigurationErrorsException( SR.NoDefaultLoggingProviderFound(SectionName), property.Source, property.LineNumber); } return(defaultProvider); }
// Throws a ConfigurationException (or a descendant) on failure. private static LoggingProviderCollection LoadAndInitializeProviderCollection(LoggingSection section) { LoggingProviderCollection providerCollection = new LoggingProviderCollection(); foreach (ProviderSettings settings in section.Providers) { LoggingProviderBase loggingProvider = InstantiateLoggingProvider(settings); providerCollection.Add(loggingProvider); } providerCollection.SetReadOnly(); return(providerCollection); }
private LoggingProviderBase[] GetReferencedProviders(LoggingProviderCollection configuredProviders) { var providers = new List <LoggingProviderBase>(); foreach (string providerName in this.providerNames) { var provider = configuredProviders[providerName]; if (configuredProviders[providerName] == null) { throw new ProviderException(SR.ReferencedProviderDoesNotExist(this, providerName)); } providers.Add(provider); } return(providers.ToArray()); }
private static void InitializeFallbackProvider(LoggingProviderBase provider, LoggingProviderCollection providers) { if (provider.FallbackProviderName != null) { // Fetch the fallback provider with the defined name from the providers collection LoggingProviderBase fallbackProvider = providers[provider.FallbackProviderName]; // Throw an exception when that provider could not be found. if (fallbackProvider == null) { throw new ProviderException( SR.InvalidFallbackProviderPropertyInConfig(SectionName, provider)); } // Initialize the provider's fallback provider with the found provider. provider.FallbackProvider = fallbackProvider; } }
internal virtual void CompleteInitialization(LoggingProviderCollection configuredProviders, LoggingProviderBase defaultProvider) { // Default implementation is empty. }
private void InitializeProviders(LoggingProviderCollection configuredProviders) { var providers = this.GetReferencedProviders(configuredProviders); this.providers = new ReadOnlyCollection <LoggingProviderBase>(providers); }