using System; using System.Globalization; namespace SweetLib.Utils.Logger.Message { /// /// contains all event log data which should be logged in as a single log message. /// public class LogMessage : IFormattable { /// /// The of this event log. /// public LogLevel LogLevel { get; } /// /// The message of this event log. /// public string Message { get; } /// /// The date and time of this event log. /// public DateTime LogDateTime { get; } /// /// Creates a new instance. will be the . /// /// The log level of this event log. /// The message of this event log. public LogMessage(LogLevel logLevel, string message) : this(logLevel, message, DateTime.Now) { } /// /// Creates a new instance. /// /// The log level of this event log. /// The message of this event log. /// The of this event log. public LogMessage(LogLevel logLevel, string message, DateTime logDateTime) { if (message == null) throw new ArgumentNullException(nameof(message)); if (logDateTime == null) throw new ArgumentNullException(nameof(logDateTime)); LogLevel = logLevel; Message = message; LogDateTime = logDateTime; } /// /// Generates a formatted of this event log. will be used to format this event log. /// /// A formated of this event log. public override string ToString() { return ToString(LogMessageFormatter.DefaultFormatString, CultureInfo.CurrentCulture); } /// /// Generates a formatted of this event log with a given format. /// /// The format to be used. See for more format information. /// Optional, an interface to be used while formatting if needed. /// A formated of this event log. public string ToString(string format, IFormatProvider formatProvider = null) { return LogMessageFormatter.Instance.Format(format, this, formatProvider); } } }