示例#1
0
        /// <summary>
        /// Write a new log object into an Xml file
        /// </summary>
        /// <param name="logOptions">The log object that implement <b><see cref="ILogOptions"/></b></param>
        private void LogToXmlFile(ILogOptions logOptions)
        {
            if (LogFileBuilder.IsFileExists(_logFileOptions.Path))
            {
                // Load the created xml log file
                var xDoc = XDocument.Load(_logFileOptions.Path);

                // Build the new log as Xml Element
                var logElement =
                    new XElement("Log",
                                 new XAttribute(nameof(logOptions.LogLevel),
                                                logOptions.LogLevel),
                                 new XAttribute(nameof(logOptions.DateTime),
                                                logOptions.DateTime
                                                .ToString("MM/dd/yyyy hh:mm:ss.fff")),
                                 new XAttribute(nameof(logOptions.MessageTemplate),
                                                logOptions.MessageTemplate));

                // Add and save the log element to the log xml file
                xDoc.Root?.Add(logElement);
                xDoc.Save(_logFileOptions.Path);
            }
            else
            {
                // If the xml log file not created yet this method will recall itself
                LogToXmlFile(logOptions);
            }
        }
示例#2
0
        /// <inheritdoc />
        protected override void ClearLog()
        {
            // Delete the old file
            File.Delete(_logFileOptions.Path);

            // Build new one
            LogFileBuilder.BuildOne(_logFileOptions);
        }
示例#3
0
 public LogFile(LogFileOptions logFileOptions)
 {
     _logFileOptions = logFileOptions;
     LogFileBuilder.BuildOne(logFileOptions);
 }