示例#1
0
        public void Log(LogEntry logEntry)
        {
            switch (logEntry.Format)
            {
            case "json":
                var serializedLogEntry = JsonSerializer.Serialize(logEntry);
                _logOutput.Save(serializedLogEntry);
                break;

            case "xml":
                var xDocument = new XDocument(
                    new XDeclaration("1.0", "UTF-8", "yes"),
                    new XElement("Root-name",
                                 new XAttribute("Log", "Log Information"),
                                 new XElement("Details", "Log Details"),
                                 new XAttribute("Time", logEntry.Timestamp),
                                 new XAttribute("Message", logEntry.Message),
                                 new XAttribute("Tags", logEntry.Tags)));
                _logOutput.Save(xDocument.ToString());
                break;

            default:
                break;
            }
        }
示例#2
0
        public void Log(LogEntry logEntry)
        {
            XmlSerializer xmlSerializer      = new XmlSerializer(typeof(LogEntry));
            var           serializedLogEntry = "";

            using (var sw = new StringWriter())
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(sw, settings))
                {
                    xmlSerializer.Serialize(writer, logEntry);
                    serializedLogEntry = sw.ToString();
                }
            }

            _logOutput.Save(serializedLogEntry);
        }
示例#3
0
        public void Log(LogEntry logEntry)
        {
            var serializedLogEntry = JsonSerializer.Serialize(logEntry);

            _logOutput.Save(serializedLogEntry);
        }