2017-04-12 17:08:54 +02:00
using System ;
using System.Globalization ;
namespace SweetLib.Utils.Logger.Message
{
2017-04-16 18:07:30 +02:00
/// <summary>
/// <see cref="LogMessage"/> contains all event log data which should be logged in as a single log message.
/// </summary>
2017-04-12 17:08:54 +02:00
public class LogMessage : IFormattable
{
2017-04-16 18:07:30 +02:00
/// <summary>
/// The <see cref="LogLevel"/> of this event log.
/// </summary>
2017-04-12 17:08:54 +02:00
public LogLevel LogLevel { get ; }
2017-04-12 17:12:35 +02:00
2017-04-16 18:07:30 +02:00
/// <summary>
/// The message of this event log.
/// </summary>
2017-04-12 17:08:54 +02:00
public string Message { get ; }
2017-04-12 17:12:35 +02:00
2017-04-16 18:07:30 +02:00
/// <summary>
/// The date and time of this event log.
/// </summary>
2017-04-12 17:08:54 +02:00
public DateTime LogDateTime { get ; }
2017-04-16 18:07:30 +02:00
/// <summary>
/// Creates a new <see cref="LogMessage"/> instance. <see cref="DateTime.Now"/> will be the <see cref="LogDateTime"/>.
/// </summary>
/// <param name="logLevel">The log level of this event log.</param>
/// <param name="message">The message of this event log.</param>
2017-04-12 17:08:54 +02:00
public LogMessage ( LogLevel logLevel , string message ) : this ( logLevel , message , DateTime . Now ) { }
2017-04-16 18:07:30 +02:00
/// <summary>
/// Creates a new <see cref="LogMessage"/> instance.
/// </summary>
/// <param name="logLevel">The log level of this event log.</param>
/// <param name="message">The message of this event log.</param>
/// <param name="logDateTime">The <see cref="DateTime"/> of this event log.</param>
2017-04-12 17:08:54 +02:00
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 ;
}
2017-04-16 18:07:30 +02:00
/// <summary>
/// Generates a formatted <see cref="string"/> of this event log. <see cref="LogMessageFormatter.DefaultFormatString"/> will be used to format this event log.
/// </summary>
/// <returns>A formated <see cref="string"/> of this event log.</returns>
2017-04-12 17:08:54 +02:00
public override string ToString ( )
{
2017-04-12 17:12:35 +02:00
return ToString ( LogMessageFormatter . DefaultFormatString , CultureInfo . CurrentCulture ) ;
2017-04-12 17:08:54 +02:00
}
2017-04-16 18:07:30 +02:00
/// <summary>
/// Generates a formatted <see cref="string"/> of this event log with a given format.
/// </summary>
/// <param name="format">The format to be used. See <see cref="LogMessageFormatter"/> for more format information.</param>
/// <param name="formatProvider">Optional, an <see cref="IFormatProvider"/> interface to be used while formatting if needed.</param>
/// <returns>A formated <see cref="string"/> of this event log.</returns>
public string ToString ( string format , IFormatProvider formatProvider = null )
2017-04-12 17:08:54 +02:00
{
return LogMessageFormatter . Instance . Format ( format , this , formatProvider ) ;
}
}
}