/// <summary> /// Parse {configuration} xml element. /// </summary> /// <param name="configurationElement"></param> /// <param name="filePath">path to config file.</param> /// <param name="autoReloadDefault">The default value for the autoReload option.</param> private void ParseConfigurationElement(NLogXmlElement configurationElement, string filePath, bool autoReloadDefault) { InternalLogger.Trace("ParseConfigurationElement"); configurationElement.AssertName("configuration"); var nlogElements = configurationElement.Elements("nlog").ToList(); foreach (var nlogElement in nlogElements) { this.ParseNLogElement(nlogElement, filePath, autoReloadDefault); } }
/// <summary> /// Parse {Rules} xml element /// </summary> /// <param name="rulesElement"></param> /// <param name="rulesCollection">Rules are added to this parameter.</param> private void ParseRulesElement(NLogXmlElement rulesElement, IList <LoggingRule> rulesCollection) { InternalLogger.Trace("ParseRulesElement"); rulesElement.AssertName("rules"); var loggerElements = rulesElement.Elements("logger").ToList(); foreach (var loggerElement in loggerElements) { this.ParseLoggerElement(loggerElement, rulesCollection); } }
private void ParseExtensionsElement(NLogXmlElement extensionsElement, string baseDirectory) { extensionsElement.AssertName("extensions"); var addElements = extensionsElement.Elements("add").ToList(); foreach (var addElement in addElements) { string prefix = addElement.GetOptionalAttribute("prefix", null); if (prefix != null) { prefix = prefix + "."; } string type = StripOptionalNamespacePrefix(addElement.GetOptionalAttribute("type", null)); if (type != null) { this.ConfigurationItemFactory.RegisterType(Type.GetType(type, true), prefix); } string assemblyFile = addElement.GetOptionalAttribute("assemblyFile", null); if (assemblyFile != null) { try { #if SILVERLIGHT && !WINDOWS_PHONE var si = Application.GetResourceStream(new Uri(assemblyFile, UriKind.Relative)); var assemblyPart = new AssemblyPart(); Assembly asm = assemblyPart.Load(si.Stream); #else string fullFileName = Path.Combine(baseDirectory, assemblyFile); InternalLogger.Info("Loading assembly file: {0}", fullFileName); Assembly asm = Assembly.LoadFrom(fullFileName); #endif this.ConfigurationItemFactory.RegisterItemsFromAssembly(asm, prefix); } catch (Exception exception) { if (exception.MustBeRethrownImmediately()) { throw; } InternalLogger.Error(exception, "Error loading extensions."); if (exception.MustBeRethrown()) { throw new NLogConfigurationException("Error loading extensions: " + assemblyFile, exception); } } continue; } string assemblyName = addElement.GetOptionalAttribute("assembly", null); if (assemblyName != null) { try { InternalLogger.Info("Loading assembly name: {0}", assemblyName); #if SILVERLIGHT && !WINDOWS_PHONE var si = Application.GetResourceStream(new Uri(assemblyName + ".dll", UriKind.Relative)); var assemblyPart = new AssemblyPart(); Assembly asm = assemblyPart.Load(si.Stream); #else Assembly asm = Assembly.Load(assemblyName); #endif this.ConfigurationItemFactory.RegisterItemsFromAssembly(asm, prefix); } catch (Exception exception) { if (exception.MustBeRethrownImmediately()) { throw; } InternalLogger.Error(exception, "Error loading extensions."); if (exception.MustBeRethrown()) { throw new NLogConfigurationException("Error loading extensions: " + assemblyName, exception); } } } } }
private void ParseExtensionsElement(NLogXmlElement extensionsElement, string baseDirectory) { extensionsElement.AssertName("extensions"); foreach (var addElement in extensionsElement.Elements("add")) { string prefix = addElement.GetOptionalAttribute("prefix", null); if (prefix != null) { prefix = prefix + "."; } string type = StripOptionalNamespacePrefix(addElement.GetOptionalAttribute("type", null)); if (type != null) { this.ConfigurationItemFactory.RegisterType(Type.GetType(type, true), prefix); } string assemblyFile = addElement.GetOptionalAttribute("assemblyFile", null); if (assemblyFile != null) { try { #if SILVERLIGHT && !WINDOWS_PHONE var si = Application.GetResourceStream(new Uri(assemblyFile, UriKind.Relative)); var assemblyPart = new AssemblyPart(); Assembly asm = assemblyPart.Load(si.Stream); #else string fullFileName = Path.Combine(baseDirectory, assemblyFile); InternalLogger.Info("Loading assembly file: {0}", fullFileName); Assembly asm = Assembly.LoadFrom(fullFileName); #endif this.ConfigurationItemFactory.RegisterItemsFromAssembly(asm, prefix); } catch (Exception exception) { if (exception.MustBeRethrown()) { throw; } InternalLogger.Error("Error loading extensions: {0}", exception); if (LogManager.ThrowExceptions) { throw new NLogConfigurationException("Error loading extensions: " + assemblyFile, exception); } } continue; } string assemblyName = addElement.GetOptionalAttribute("assembly", null); if (assemblyName != null) { try { InternalLogger.Info("Loading assembly name: {0}", assemblyName); #if SILVERLIGHT && !WINDOWS_PHONE var si = Application.GetResourceStream(new Uri(assemblyName + ".dll", UriKind.Relative)); var assemblyPart = new AssemblyPart(); Assembly asm = assemblyPart.Load(si.Stream); #else Assembly asm = Assembly.Load(assemblyName); #endif this.ConfigurationItemFactory.RegisterItemsFromAssembly(asm, prefix); } catch (Exception exception) { if (exception.MustBeRethrown()) { throw; } InternalLogger.Error("Error loading extensions: {0}", exception); if (LogManager.ThrowExceptions) { throw new NLogConfigurationException("Error loading extensions: " + assemblyName, exception); } } continue; } } }
/// <summary> /// Parse {Rules} xml element /// </summary> /// <param name="rulesElement"></param> /// <param name="rulesCollection">Rules are added to this parameter.</param> private void ParseRulesElement(NLogXmlElement rulesElement, IList<LoggingRule> rulesCollection) { InternalLogger.Trace("ParseRulesElement"); rulesElement.AssertName("rules"); foreach (var loggerElement in rulesElement.Elements("logger")) { this.ParseLoggerElement(loggerElement, rulesCollection); } }
/// <summary> /// Parse {configuration} xml element. /// </summary> /// <param name="configurationElement"></param> /// <param name="filePath">path to config file.</param> /// <param name="autoReloadDefault">The default value for the autoReload option.</param> private void ParseConfigurationElement(NLogXmlElement configurationElement, string filePath, bool autoReloadDefault) { InternalLogger.Trace("ParseConfigurationElement"); configurationElement.AssertName("configuration"); foreach (var el in configurationElement.Elements("nlog")) { this.ParseNLogElement(el, filePath, autoReloadDefault); } }
private void ParseConfigurationElement(NLogXmlElement configurationElement, string baseDirectory) { InternalLogger.Trace("ParseConfigurationElement"); configurationElement.AssertName("configuration"); foreach (var el in configurationElement.Elements("nlog")) { this.ParseNLogElement(el, baseDirectory); } }