Save() public méthode

Saves this instance to an XML string.
public Save ( ) : string
Résultat string
        /// <summary>
        /// Appends the specified builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="logEventInfo">The log event info.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEventInfo)
        {
            var logEvent = new LogEvent();
            logEvent.Populate(logEventInfo);

            string xml = logEvent.Save();
            builder.Append(xml);
        }
        public void NestedErrorWrite()
        {
            LogEvent logEvent = new LogEvent();

            string path = "blah.txt";
            try
            {
                try
                {
                    string text = File.ReadAllText(path);
                }
                catch (Exception ioex)
                {
                    throw new ApplicationException("Error reading file.", ioex);
                }
            }
            catch (Exception ex)
            {
                var log = _logger.Error()
                    .Message("Error reading file '{0}'.", path)
                    .Exception(ex)
                    .Property("Test", "ErrorWrite")
                    .LogEventInfo;

                logEvent.Populate(log);
            }

            string fileName = string.Format("LogEvent-{0}.xml", DateTime.Now.Ticks);

            string xml = logEvent.Save();
            File.WriteAllText(fileName, xml);

            string outputFileName = Path.ChangeExtension(fileName, ".Writer.xml");

            var settings = new XmlWriterSettings { Indent = true };
            var writer = XmlWriter.Create(outputFileName, settings);
            var eventWriter = new LogEventWriter();

            eventWriter.Write(writer, logEvent);
            writer.Flush();
            writer.Close();

            string newXml = File.ReadAllText(outputFileName);
            var newEvent = LogEvent.Load(newXml);
            newEvent.Should().NotBeNull();
        }