/// <summary> /// Loads the configuration from an XDocument object /// </summary> /// <param name="configDoc">The XML document object</param> /// <returns>The populated LoggingConfiguration object</returns> private static LoggingConfiguration LoadConfiguration(XDocument configDoc) { LoggingConfigElement loggingConfigElement = LoggingConfigElement.Parse( configDoc.Element(LoggingConfigElement.TAG) ); return(loggingConfigElement.ToLoggingConfiguration()); }
/// <summary> /// Parses a LoggingConfig XML element /// </summary> /// <param name="element">The XML element</param> /// <returns>A populated LoggingConfigElement</returns> public static LoggingConfigElement Parse(XElement element) { if (element == null) { throw new FormatException($"'{TAG}' tag not found."); } XAttribute fileNameAttribute = element.Attribute(FILE_NAME_ATTRIBUTE); XAttribute windowsPathAttribute = element.Attribute(WINDOWS_PATH_ATTRIBUTE); XAttribute linuxPathAttribute = element.Attribute(LINUX_PATH_ATTIRBUTE); if (fileNameAttribute == null) { throw new FormatException($"'{FILE_NAME_ATTRIBUTE}' attribute of {TAG} element is missing."); } if (windowsPathAttribute == null) { throw new FormatException($"'{WINDOWS_PATH_ATTRIBUTE}' attribute of {TAG} element is missing."); } if (linuxPathAttribute == null) { throw new FormatException($"'{LINUX_PATH_ATTIRBUTE}' attribute of {TAG} element is missing."); } LoggingConfigElement configElement = new LoggingConfigElement( windowsPathAttribute.Value, linuxPathAttribute.Value, fileNameAttribute.Value ); foreach (XElement typeElement in element.Elements(LoggingTypeElement.TAG)) { configElement.AddLoggingType(LoggingTypeElement.Parse(typeElement)); } return(configElement); }