Example #1
0
        /// <summary>
        /// Save a LoggerRoot object to the filesystem
        /// </summary>
        /// <param name="filePath">The path where the LoggerRoot object should be stored</param>
        /// <param name="root">The LoggerRoot object that should be saved</param>
        /// <param name="saveFormat">The format in which the LoggerRoot object should be stored</param>
        internal static void SaveLoggerRoot(string filePath, LoggerRoot root, SaveFormats saveFormat)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(nameof(filePath));
            }
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            switch (saveFormat)
            {
            case SaveFormats.Xml:
                SaveLoggerRootXml(filePath, root);
                break;

            case SaveFormats.Json:
                SaveLoggerRootJson(filePath, root);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(saveFormat), saveFormat, null);
            }
        }
Example #2
0
        /// <summary>
        /// Save a LoggerRoot object to the filesystem in JSON format
        /// </summary>
        /// <param name="filePath">The path where the LoggerRoot object should be stored</param>
        /// <param name="root">The LoggerRoot object that should be saved</param>
        private static void SaveLoggerRootJson(string filePath, LoggerRoot root)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer(new SimpleTypeResolver());
            string json = serializer.Serialize(root);

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(json);
            }
        }
Example #3
0
        /// <summary>
        /// Save a LoggerRoot object to the filesystem in XML format
        /// </summary>
        /// <param name="filePath">The path where the LoggerRoot object should be stored</param>
        /// <param name="root">The LoggerRoot object that should be saved</param>
        private static void SaveLoggerRootXml(string filePath, LoggerRoot root)
        {
            XmlSerializer xsSubmit = new XmlSerializer(typeof(LoggerRoot));
            string        xml;

            using (StringWriter sww = new StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(sww))
                {
                    xsSubmit.Serialize(writer, root);
                    xml = sww.ToString();
                }
            }

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(xml);
            }
        }