public string ConfigFileFullPath(Assembly assembly) { string text1 = null; if ((this._configFile == null) || (this._configFile.Length == 0)) { if ((this._configFileExtension == null) || (this._configFileExtension.Length == 0)) { text1 = SystemInfo.ConfigurationFileLocation; } else { if (this._configFileExtension[0] != '.') { this._configFileExtension = "." + this._configFileExtension; } text1 = Path.Combine(SystemInfo.ApplicationBaseDirectory, SystemInfo.AssemblyFileName(assembly) + this._configFileExtension); } } else { text1 = Path.Combine(SystemInfo.ApplicationBaseDirectory, this._configFile); } return(text1); }
/// <summary> /// Attempt to load configuration from the local file system /// </summary> /// <param name="sourceAssembly">The assembly that this attribute was defined on.</param> /// <param name="targetRepository">The repository to configure.</param> private void ConfigureFromFile(Assembly sourceAssembly, ILoggerRepository targetRepository) { string text = null; if (m_configFile == null || m_configFile.Length == 0) { if (m_configFileExtension == null || m_configFileExtension.Length == 0) { try { text = SystemInfo.ConfigurationFileLocation; } catch (Exception exception) { LogLog.Error(declaringType, "XmlConfiguratorAttribute: Exception getting ConfigurationFileLocation. Must be able to resolve ConfigurationFileLocation when ConfigFile and ConfigFileExtension properties are not set.", exception); } } else { if (m_configFileExtension[0] != '.') { m_configFileExtension = "." + m_configFileExtension; } string text2 = null; try { text2 = SystemInfo.ApplicationBaseDirectory; } catch (Exception exception2) { LogLog.Error(declaringType, "Exception getting ApplicationBaseDirectory. Must be able to resolve ApplicationBaseDirectory and AssemblyFileName when ConfigFileExtension property is set.", exception2); } if (text2 != null) { text = Path.Combine(text2, SystemInfo.AssemblyFileName(sourceAssembly) + m_configFileExtension); } } } else { string text3 = null; try { text3 = SystemInfo.ApplicationBaseDirectory; } catch (Exception exception3) { LogLog.Warn(declaringType, "Exception getting ApplicationBaseDirectory. ConfigFile property path [" + m_configFile + "] will be treated as an absolute path.", exception3); } text = ((text3 == null) ? m_configFile : Path.Combine(text3, m_configFile)); } if (text != null) { ConfigureFromFile(targetRepository, new FileInfo(text)); } }
/// <summary> /// Attempt to load configuration from the local file system. /// </summary> /// <param name="sourceAssembly">The assembly that this attribute was defined on.</param> /// <param name="targetRepository">The repository to configure.</param> private void ConfigureFromFile(Assembly sourceAssembly, ILoggerRepository targetRepository) { // Work out the full path to the config file string fullPath2ConfigFile = null; // Select the config file if (this.m_configFile == null || this.m_configFile.Length == 0) { if (this.m_configFileExtension == null || this.m_configFileExtension.Length == 0) { // Use the default .config file for the AppDomain try { fullPath2ConfigFile = SystemInfo.ConfigurationFileLocation; } catch (Exception ex) { LogLog.Error(declaringType, "XmlConfiguratorAttribute: Exception getting ConfigurationFileLocation. Must be able to resolve ConfigurationFileLocation when ConfigFile and ConfigFileExtension properties are not set.", ex); } } else { // Force the extension to start with a '.' if (this.m_configFileExtension[0] != '.') { this.m_configFileExtension = "." + this.m_configFileExtension; } string applicationBaseDirectory = null; try { applicationBaseDirectory = SystemInfo.ApplicationBaseDirectory; } catch (Exception ex) { LogLog.Error(declaringType, "Exception getting ApplicationBaseDirectory. Must be able to resolve ApplicationBaseDirectory and AssemblyFileName when ConfigFileExtension property is set.", ex); } if (applicationBaseDirectory != null) { fullPath2ConfigFile = Path.Combine(applicationBaseDirectory, SystemInfo.AssemblyFileName(sourceAssembly) + this.m_configFileExtension); } } } else { string applicationBaseDirectory = null; try { applicationBaseDirectory = SystemInfo.ApplicationBaseDirectory; } catch (Exception ex) { LogLog.Warn(declaringType, "Exception getting ApplicationBaseDirectory. ConfigFile property path [" + this.m_configFile + "] will be treated as an absolute path.", ex); } if (applicationBaseDirectory != null) { // Just the base dir + the config file fullPath2ConfigFile = Path.Combine(applicationBaseDirectory, this.m_configFile); } else { fullPath2ConfigFile = this.m_configFile; } } if (fullPath2ConfigFile != null) { this.ConfigureFromFile(targetRepository, new FileInfo(fullPath2ConfigFile)); } }
/// <summary> /// Configures the <see cref="ILoggerRepository"/> for the specified assembly. /// </summary> /// <param name="assembly">The assembly that this attribute was defined on.</param> /// <param name="repository">The repository to configure.</param> /// <remarks> /// <para> /// Configure the repository using the <see cref="DOMConfigurator"/>. /// The <paramref name="repository"/> specified must extend the <see cref="Hierarchy"/> /// class otherwise the <see cref="DOMConfigurator"/> will not be able to /// configure it. /// </para> /// </remarks> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="repository" /> does not extend <see cref="Hierarchy"/>.</exception> override public void Configure(Assembly assembly, ILoggerRepository repository) { // Ensure that the the repository extends the Hierarchy class if (!(repository is Hierarchy)) { throw new ArgumentOutOfRangeException("Parameter: repository Value: [" + repository + "] is out of range. DOMConfigurator can only configure Hierarchy objects"); } // Work out the full path to the config file string fullPath2ConfigFile = null; // Select the config file if (m_configFile == null || m_configFile.Length == 0) { if (m_configFileExtension == null || m_configFileExtension.Length == 0) { // Use the default .config file for the AppDomain fullPath2ConfigFile = SystemInfo.ConfigurationFileLocation; } else { // Force the extension to start with a '.' if (m_configFileExtension[0] != '.') { m_configFileExtension = "." + m_configFileExtension; } fullPath2ConfigFile = Path.Combine(SystemInfo.ApplicationBaseDirectory, SystemInfo.AssemblyFileName(assembly) + m_configFileExtension); } } else { // Just the base dir + the config file fullPath2ConfigFile = Path.Combine(SystemInfo.ApplicationBaseDirectory, m_configFile); } #if (SSCLI) DOMConfigurator.Configure(repository as Hierarchy, new FileInfo(fullPath2ConfigFile)); #else // Do we configure just once or do we configure and then watch? if (m_configureAndWatch) { DOMConfigurator.ConfigureAndWatch(repository as Hierarchy, new FileInfo(fullPath2ConfigFile)); } else { DOMConfigurator.Configure(repository as Hierarchy, new FileInfo(fullPath2ConfigFile)); } #endif }