/// <summary> /// Parses a logger element. /// </summary> /// <param name="loggerElement">The logger element.</param> /// <remarks> /// <para> /// Parse an XML element that represents a logger. /// </para> /// </remarks> protected void ParseLogger(XmlElement loggerElement) { string attribute = loggerElement.GetAttribute("name"); LogLog.Debug(declaringType, "Retrieving an instance of log4net.Repository.Logger for logger [" + attribute + "]."); Logger logger = m_hierarchy.GetLogger(attribute) as Logger; lock (logger) { bool additivity = OptionConverter.ToBoolean(loggerElement.GetAttribute("additivity"), defaultValue: true); LogLog.Debug(declaringType, "Setting [" + logger.Name + "] additivity to [" + additivity.ToString() + "]."); logger.Additivity = additivity; ParseChildrenOfLoggerElement(loggerElement, logger, isRoot: false); } }
protected void ParseLogger(XmlElement loggerElement) { string attribute = loggerElement.GetAttribute("name"); LogLog.Debug(declaringType, "Retrieving an instance of log4net.Repository.Logger for logger [" + attribute + "]."); Logger log = this.m_hierarchy.GetLogger(attribute) as Logger; lock (log) { bool flag = OptionConverter.ToBoolean(loggerElement.GetAttribute("additivity"), true); object[] objArray1 = new object[] { "Setting [", log.Name, "] additivity to [", flag, "]." }; LogLog.Debug(declaringType, string.Concat(objArray1)); log.Additivity = flag; this.ParseChildrenOfLoggerElement(loggerElement, log, false); } }
/// <summary> /// Parses a logger element. /// </summary> /// <param name="loggerElement">The logger element.</param> /// <remarks> /// <para> /// Parse an XML element that represents a logger. /// </para> /// </remarks> protected void ParseLogger(XmlElement loggerElement) { // Create a new GodLesZ.Library.Logging.Logger object from the <logger> element. string loggerName = loggerElement.GetAttribute(NAME_ATTR); LogLog.Debug(declaringType, "Retrieving an instance of GodLesZ.Library.Logging.Repository.Logger for logger [" + loggerName + "]."); Logger log = m_hierarchy.GetLogger(loggerName) as Logger; // Setting up a logger needs to be an atomic operation, in order // to protect potential log operations while logger // configuration is in progress. lock (log) { bool additivity = OptionConverter.ToBoolean(loggerElement.GetAttribute(ADDITIVITY_ATTR), true); LogLog.Debug(declaringType, "Setting [" + log.Name + "] additivity to [" + additivity + "]."); log.Additivity = additivity; ParseChildrenOfLoggerElement(loggerElement, log, false); } }
/// <summary> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </summary> /// <param name="element">The root element to parse.</param> /// <remarks> /// <para> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </para> /// </remarks> public void Configure(XmlElement element) { if (element == null || m_hierarchy == null) { return; } string rootElementName = element.LocalName; if (rootElementName != CONFIGURATION_TAG) { LogLog.Error(declaringType, "Xml element is - not a <" + CONFIGURATION_TAG + "> element."); return; } if (!LogLog.EmitInternalMessages) { // Look for a emitDebug attribute to enable internal debug string emitDebugAttribute = element.GetAttribute(EMIT_INTERNAL_DEBUG_ATTR); LogLog.Debug(declaringType, EMIT_INTERNAL_DEBUG_ATTR + " attribute [" + emitDebugAttribute + "]."); if (emitDebugAttribute.Length > 0 && emitDebugAttribute != "null") { LogLog.EmitInternalMessages = OptionConverter.ToBoolean(emitDebugAttribute, true); } else { LogLog.Debug(declaringType, "Ignoring " + EMIT_INTERNAL_DEBUG_ATTR + " attribute."); } } if (!LogLog.InternalDebugging) { // Look for a debug attribute to enable internal debug string debugAttribute = element.GetAttribute(INTERNAL_DEBUG_ATTR); LogLog.Debug(declaringType, INTERNAL_DEBUG_ATTR + " attribute [" + debugAttribute + "]."); if (debugAttribute.Length > 0 && debugAttribute != "null") { LogLog.InternalDebugging = OptionConverter.ToBoolean(debugAttribute, true); } else { LogLog.Debug(declaringType, "Ignoring " + INTERNAL_DEBUG_ATTR + " attribute."); } string confDebug = element.GetAttribute(CONFIG_DEBUG_ATTR); if (confDebug.Length > 0 && confDebug != "null") { LogLog.Warn(declaringType, "The \"" + CONFIG_DEBUG_ATTR + "\" attribute is deprecated."); LogLog.Warn(declaringType, "Use the \"" + INTERNAL_DEBUG_ATTR + "\" attribute instead."); LogLog.InternalDebugging = OptionConverter.ToBoolean(confDebug, true); } } // Default mode is merge ConfigUpdateMode configUpdateMode = ConfigUpdateMode.Merge; // Look for the config update attribute string configUpdateModeAttribute = element.GetAttribute(CONFIG_UPDATE_MODE_ATTR); if (configUpdateModeAttribute != null && configUpdateModeAttribute.Length > 0) { // Parse the attribute try { configUpdateMode = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), configUpdateModeAttribute); } catch { LogLog.Error(declaringType, "Invalid " + CONFIG_UPDATE_MODE_ATTR + " attribute value [" + configUpdateModeAttribute + "]"); } } // IMPL: The IFormatProvider argument to Enum.ToString() is deprecated in .NET 2.0 LogLog.Debug(declaringType, "Configuration update mode [" + configUpdateMode.ToString() + "]."); // Only reset configuration if overwrite flag specified if (configUpdateMode == ConfigUpdateMode.Overwrite) { // Reset to original unset configuration m_hierarchy.ResetConfiguration(); LogLog.Debug(declaringType, "Configuration reset before reading config."); } /* Building Appender objects, placing them in a local namespace * for future reference */ /* Process all the top level elements */ foreach (XmlNode currentNode in element.ChildNodes) { if (currentNode.NodeType == XmlNodeType.Element) { XmlElement currentElement = (XmlElement)currentNode; if (currentElement.LocalName == LOGGER_TAG) { ParseLogger(currentElement); } else if (currentElement.LocalName == CATEGORY_TAG) { // TODO: deprecated use of category ParseLogger(currentElement); } else if (currentElement.LocalName == ROOT_TAG) { ParseRoot(currentElement); } else if (currentElement.LocalName == RENDERER_TAG) { ParseRenderer(currentElement); } else if (currentElement.LocalName == APPENDER_TAG) { // We ignore appenders in this pass. They will // be found and loaded if they are referenced. } else { // Read the param tags and set properties on the hierarchy SetParameter(currentElement, m_hierarchy); } } } // Lastly set the hierarchy threshold string thresholdStr = element.GetAttribute(THRESHOLD_ATTR); LogLog.Debug(declaringType, "Hierarchy Threshold [" + thresholdStr + "]"); if (thresholdStr.Length > 0 && thresholdStr != "null") { Level thresholdLevel = (Level)ConvertStringTo(typeof(Level), thresholdStr); if (thresholdLevel != null) { m_hierarchy.Threshold = thresholdLevel; } else { LogLog.Warn(declaringType, "Unable to set hierarchy threshold using value [" + thresholdStr + "] (with acceptable conversion types)"); } } // Done reading config }
/// <summary> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </summary> /// <param name="element">The root element to parse.</param> /// <remarks> /// <para> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </para> /// </remarks> public void Configure(XmlElement element) { if (element == null || m_hierarchy == null) { return; } if (element.LocalName != "log4net") { LogLog.Error(declaringType, "Xml element is - not a <log4net> element."); return; } if (!LogLog.EmitInternalMessages) { string attribute = element.GetAttribute("emitDebug"); LogLog.Debug(declaringType, "emitDebug attribute [" + attribute + "]."); if (attribute.Length > 0 && attribute != "null") { LogLog.EmitInternalMessages = OptionConverter.ToBoolean(attribute, defaultValue: true); } else { LogLog.Debug(declaringType, "Ignoring emitDebug attribute."); } } if (!LogLog.InternalDebugging) { string attribute2 = element.GetAttribute("debug"); LogLog.Debug(declaringType, "debug attribute [" + attribute2 + "]."); if (attribute2.Length > 0 && attribute2 != "null") { LogLog.InternalDebugging = OptionConverter.ToBoolean(attribute2, defaultValue: true); } else { LogLog.Debug(declaringType, "Ignoring debug attribute."); } string attribute3 = element.GetAttribute("configDebug"); if (attribute3.Length > 0 && attribute3 != "null") { LogLog.Warn(declaringType, "The \"configDebug\" attribute is deprecated."); LogLog.Warn(declaringType, "Use the \"debug\" attribute instead."); LogLog.InternalDebugging = OptionConverter.ToBoolean(attribute3, defaultValue: true); } } ConfigUpdateMode configUpdateMode = ConfigUpdateMode.Merge; string attribute4 = element.GetAttribute("update"); if (attribute4 != null && attribute4.Length > 0) { try { configUpdateMode = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), attribute4); } catch { LogLog.Error(declaringType, "Invalid update attribute value [" + attribute4 + "]"); } } LogLog.Debug(declaringType, "Configuration update mode [" + configUpdateMode.ToString() + "]."); if (configUpdateMode == ConfigUpdateMode.Overwrite) { m_hierarchy.ResetConfiguration(); LogLog.Debug(declaringType, "Configuration reset before reading config."); } foreach (XmlNode childNode in element.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element) { XmlElement xmlElement = (XmlElement)childNode; if (xmlElement.LocalName == "logger") { ParseLogger(xmlElement); } else if (xmlElement.LocalName == "category") { ParseLogger(xmlElement); } else if (xmlElement.LocalName == "root") { ParseRoot(xmlElement); } else if (xmlElement.LocalName == "renderer") { ParseRenderer(xmlElement); } else if (!(xmlElement.LocalName == "appender")) { SetParameter(xmlElement, m_hierarchy); } } } string attribute5 = element.GetAttribute("threshold"); LogLog.Debug(declaringType, "Hierarchy Threshold [" + attribute5 + "]"); if (attribute5.Length > 0 && attribute5 != "null") { Level level = (Level)ConvertStringTo(typeof(Level), attribute5); if (level != null) { m_hierarchy.Threshold = level; } else { LogLog.Warn(declaringType, "Unable to set hierarchy threshold using value [" + attribute5 + "] (with acceptable conversion types)"); } } }
/// <summary> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </summary> /// <param name="element">The root element to parse.</param> /// <remarks> /// <para> /// Configure the hierarchy by parsing a DOM tree of XML elements. /// </para> /// </remarks> public void Configure(XmlElement element) { if (element == null || m_hierarchy == null) { return; } string rootelementname = element.LocalName; if (rootelementname != CONFIGURATION_TAG) { LogLog.Error(declaringType, "Xml element is - not a <" + CONFIGURATION_TAG + "> element."); return; } string quietModeAttribute = element.GetAttribute(QUIETMODE_ATTR); LogLog.Debug(declaringType, QUIETMODE_ATTR + " attribute [" + quietModeAttribute + "]."); if (quietModeAttribute.Length > 0 && quietModeAttribute != "null") { LogLog.QuietMode = OptionConverter.ToBoolean(quietModeAttribute, false); } else { LogLog.Debug(declaringType, "Ignoring " + QUIETMODE_ATTR + " attribute."); } if (!LogLog.EmitInternalMessages) { // Look for a emitDebug attribute to enable internal debug string emitDebugAttribute = element.GetAttribute(EMIT_INTERNAL_DEBUG_ATTR); LogLog.Debug(declaringType, EMIT_INTERNAL_DEBUG_ATTR + " attribute [" + emitDebugAttribute + "]."); if (emitDebugAttribute.Length > 0 && emitDebugAttribute != "null") { LogLog.EmitInternalMessages = OptionConverter.ToBoolean(emitDebugAttribute, true); } else { LogLog.Debug(declaringType, "Ignoring " + EMIT_INTERNAL_DEBUG_ATTR + " attribute."); } } if (!LogLog.InternalDebugging) { // Look for a debug attribute to enable internal debug string debugAttribute = element.GetAttribute(INTERNAL_DEBUG_ATTR); LogLog.Debug(declaringType, INTERNAL_DEBUG_ATTR + " attribute [" + debugAttribute + "]."); if (debugAttribute.Length > 0 && debugAttribute != "null") { LogLog.InternalDebugging = OptionConverter.ToBoolean(debugAttribute, true); } else { LogLog.Debug(declaringType, "Ignoring " + INTERNAL_DEBUG_ATTR + " attribute."); } } foreach (XmlNode node in element.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } XmlElement xe = (XmlElement)node; if (xe.LocalName == LOGGER_TAG) { ParseLogger(xe); } else if (xe.LocalName == APPENDER_TAG) { //.... } else if (xe.LocalName == PLUGINS) { ParsePlugins(xe); } else { SetParameter(xe, m_hierarchy); } } //if (rootelementname != }
public void Configure(XmlElement element) { if ((element != null) && (this.m_hierarchy != null)) { if (element.LocalName != "log4net") { LogLog.Error(declaringType, "Xml element is - not a <log4net> element."); } else { if (!LogLog.EmitInternalMessages) { string argValue = element.GetAttribute("emitDebug"); LogLog.Debug(declaringType, "emitDebug attribute [" + argValue + "]."); if ((argValue.Length > 0) && (argValue != "null")) { LogLog.EmitInternalMessages = OptionConverter.ToBoolean(argValue, true); } else { LogLog.Debug(declaringType, "Ignoring emitDebug attribute."); } } if (!LogLog.InternalDebugging) { string argValue = element.GetAttribute("debug"); LogLog.Debug(declaringType, "debug attribute [" + argValue + "]."); if ((argValue.Length > 0) && (argValue != "null")) { LogLog.InternalDebugging = OptionConverter.ToBoolean(argValue, true); } else { LogLog.Debug(declaringType, "Ignoring debug attribute."); } string str4 = element.GetAttribute("configDebug"); if ((str4.Length > 0) && (str4 != "null")) { LogLog.Warn(declaringType, "The \"configDebug\" attribute is deprecated."); LogLog.Warn(declaringType, "Use the \"debug\" attribute instead."); LogLog.InternalDebugging = OptionConverter.ToBoolean(str4, true); } } ConfigUpdateMode merge = ConfigUpdateMode.Merge; string attribute = element.GetAttribute("update"); if ((attribute != null) && (attribute.Length > 0)) { try { merge = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), attribute); } catch { LogLog.Error(declaringType, "Invalid update attribute value [" + attribute + "]"); } } LogLog.Debug(declaringType, "Configuration update mode [" + merge.ToString() + "]."); if (merge == ConfigUpdateMode.Overwrite) { this.m_hierarchy.ResetConfiguration(); LogLog.Debug(declaringType, "Configuration reset before reading config."); } IEnumerator enumerator = element.ChildNodes.GetEnumerator(); try { while (enumerator.MoveNext()) { XmlNode current = (XmlNode)enumerator.Current; if (current.NodeType == XmlNodeType.Element) { XmlElement loggerElement = (XmlElement)current; if (loggerElement.LocalName == "logger") { this.ParseLogger(loggerElement); continue; } if (loggerElement.LocalName == "category") { this.ParseLogger(loggerElement); continue; } if (loggerElement.LocalName == "root") { this.ParseRoot(loggerElement); continue; } if (loggerElement.LocalName == "renderer") { this.ParseRenderer(loggerElement); continue; } if (loggerElement.LocalName != "appender") { this.SetParameter(loggerElement, this.m_hierarchy); } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } string str6 = element.GetAttribute("threshold"); LogLog.Debug(declaringType, "Hierarchy Threshold [" + str6 + "]"); if ((str6.Length > 0) && (str6 != "null")) { Level level = (Level)this.ConvertStringTo(typeof(Level), str6); if (level != null) { this.m_hierarchy.Threshold = level; } else { LogLog.Warn(declaringType, "Unable to set hierarchy threshold using value [" + str6 + "] (with acceptable conversion types)"); } } } } }