/// <summary> /// Configures the <see cref="ILoggerRepository"/> using the file specified, /// monitors the file for changes and reloads the configuration if a change /// is detected. /// </summary> /// <param name="repository">The repository to configure.</param> /// <param name="configFile">The XML file to load the configuration from.</param> /// <remarks> /// <para> /// The configuration file must be valid XML. It must contain /// at least one element called <c>log4net</c> that holds /// the configuration data. /// </para> /// <para> /// The configuration file will be monitored using a <see cref="FileSystemWatcher"/> /// and depends on the behavior of that class. /// </para> /// <para> /// For more information on how to configure log4net using /// a separate configuration file, see <see cref="Configure(FileInfo)"/>. /// </para> /// </remarks> /// <seealso cref="Configure(FileInfo)"/> static public void ConfigureAndWatch(ILoggerRepository repository, FileInfo configFile) { LogLog.Debug("XmlConfigurator: configuring repository [" + repository.Name + "] using file [" + configFile + "] watching for file updates"); if (configFile == null) { LogLog.Error("XmlConfigurator: ConfigureAndWatch called with null 'configFile' parameter"); } else { // Configure log4net now Configure(repository, configFile); try { // Create a watch handler that will reload the // configuration whenever the config file is modified. ConfigureAndWatchHandler.StartWatching(repository, configFile); } catch (Exception ex) { LogLog.Error("XmlConfigurator: Failed to initialize configuration file watcher for file [" + configFile.FullName + "]", ex); } } }
static private void InternalConfigureAndWatch(ILoggerRepository repository, FileInfo configFile) { LogLog.Debug(declaringType, "configuring repository [" + repository.Name + "] using file [" + configFile + "] watching for file updates"); if (configFile == null) { LogLog.Error(declaringType, "ConfigureAndWatch called with null 'configFile' parameter"); } else { // Configure GodLesZ.Library.Logging now InternalConfigure(repository, configFile); try { lock (m_repositoryName2ConfigAndWatchHandler) { // support multiple repositories each having their own watcher ConfigureAndWatchHandler handler = (ConfigureAndWatchHandler)m_repositoryName2ConfigAndWatchHandler[repository.Name]; if (handler != null) { m_repositoryName2ConfigAndWatchHandler.Remove(repository.Name); handler.Dispose(); } // Create and start a watch handler that will reload the // configuration whenever the config file is modified. handler = new ConfigureAndWatchHandler(repository, configFile); m_repositoryName2ConfigAndWatchHandler[repository.Name] = handler; } } catch (Exception ex) { LogLog.Error(declaringType, "Failed to initialize configuration file watcher for file [" + configFile.FullName + "]", ex); } } }
private static void InternalConfigureAndWatch(ILoggerRepository repository, FileInfo configFile) { LogLog.Debug(declaringType, "configuring repository [" + repository.Name + "] using file [" + configFile + "] watching for file updates"); if (configFile == null) { LogLog.Error(declaringType, "ConfigureAndWatch called with null 'configFile' parameter"); return; } InternalConfigure(repository, configFile); try { lock (m_repositoryName2ConfigAndWatchHandler) { ConfigureAndWatchHandler configureAndWatchHandler = (ConfigureAndWatchHandler)m_repositoryName2ConfigAndWatchHandler[configFile.FullName]; if (configureAndWatchHandler != null) { m_repositoryName2ConfigAndWatchHandler.Remove(configFile.FullName); configureAndWatchHandler.Dispose(); } configureAndWatchHandler = new ConfigureAndWatchHandler(repository, configFile); m_repositoryName2ConfigAndWatchHandler[configFile.FullName] = configureAndWatchHandler; } } catch (Exception exception) { LogLog.Error(declaringType, "Failed to initialize configuration file watcher for file [" + configFile.FullName + "]", exception); } }
/// <summary> /// Configures TracerX using the file specified, monitors the file for changes, /// and reloads the configuration if a change is detected. /// </summary> /// <param name="configFile">The XML file to load the configuration from.</param> /// <remarks> /// <para> /// The configuration file must be valid XML. It must contain /// at least one element called <c>TracerX</c> that holds /// the configuration data. /// </para> /// <para> /// The configuration file will be monitored using a <see cref="FileSystemWatcher"/> /// and depends on the behavior of that class. /// </para> /// </remarks> static public bool ConfigureAndWatch(FileInfo configFile) { bool ret = false; if (configFile == null) { EventLogging.Log("XmlConfig: ConfigureAndWatch called with null 'configStream' parameter", EventLogging.XmlConfigError); } else { // Configure TracerX now ret = Configure(configFile); try { // Create a watch handler that will reload the // configuration whenever the config file is modified. ConfigureAndWatchHandler.StartWatching(configFile); } catch (Exception ex) { EventLogging.Log("XmlConfig: Failed to initialize configuration file watcher for file [" + configFile.FullName + "]\n" + ex.ToString(), EventLogging.XmlConfigWarning); } } return(ret); }
private static void InternalConfigureAndWatch(ILoggerRepository repository, FileInfo configFile) { object[] objArray1 = new object[] { "configuring repository [", repository.Name, "] using file [", configFile, "] watching for file updates" }; LogLog.Debug(declaringType, string.Concat(objArray1)); if (configFile == null) { LogLog.Error(declaringType, "ConfigureAndWatch called with null 'configFile' parameter"); } else { InternalConfigure(repository, configFile); try { lock (m_repositoryName2ConfigAndWatchHandler) { ConfigureAndWatchHandler handler = (ConfigureAndWatchHandler)m_repositoryName2ConfigAndWatchHandler[configFile.FullName]; if (handler != null) { m_repositoryName2ConfigAndWatchHandler.Remove(configFile.FullName); handler.Dispose(); } handler = new ConfigureAndWatchHandler(repository, configFile); m_repositoryName2ConfigAndWatchHandler[configFile.FullName] = handler; } } catch (Exception exception) { LogLog.Error(declaringType, "Failed to initialize configuration file watcher for file [" + configFile.FullName + "]", exception); } } }
static private void InternalConfigureAndWatch(ILoggerRepository repository, FileInfo configFile) { LogLog.Debug(declaringType, "configuring repository [" + repository.Name + "] using file [" + configFile + "] watching for file updates"); if (configFile == null) { LogLog.Error(declaringType, "ConfigureAndWatch called with null 'configFile' parameter"); } else { // Configure log4net now InternalConfigure(repository, configFile); try { lock (m_repositoryName2ConfigAndWatchHandler) { // support multiple repositories each having their own watcher ConfigureAndWatchHandler handler = (ConfigureAndWatchHandler)m_repositoryName2ConfigAndWatchHandler[configFile.FullName]; if (handler != null) { m_repositoryName2ConfigAndWatchHandler.Remove(configFile.FullName); handler.Dispose(); } // Create and start a watch handler that will reload the // configuration whenever the config file is modified. handler = new ConfigureAndWatchHandler(repository, configFile); m_repositoryName2ConfigAndWatchHandler[configFile.FullName] = handler; } } catch(Exception ex) { LogLog.Error(declaringType, "Failed to initialize configuration file watcher for file ["+configFile.FullName+"]", ex); } } }
/// <summary> /// Watch a specified config file used to configure a repository /// </summary> /// <param name="repository">The repository to configure.</param> /// <param name="configFile">The configuration file to watch.</param> /// <remarks> /// <para> /// Watch a specified config file used to configure a repository /// </para> /// </remarks> internal static void StartWatching(ILoggerRepository repository, FileInfo configFile) { ConfigureAndWatchHandler watcher = new ConfigureAndWatchHandler(repository, configFile); }