namespace Unosquare.Swan
{
using System;
///
/// Event arguments representing the message that is logged
/// on to the terminal. Use the properties to forward the data to
/// your logger of choice.
///
///
public class LogMessageReceivedEventArgs : EventArgs
{
///
/// Initializes a new instance of the class.
///
/// The sequence.
/// Type of the message.
/// The UTC date.
/// The source.
/// The message.
/// The extended data.
/// Name of the caller member.
/// The caller file path.
/// The caller line number.
public LogMessageReceivedEventArgs(
ulong sequence,
LogMessageType messageType,
DateTime utcDate,
string source,
string message,
object extendedData,
string callerMemberName,
string callerFilePath,
int callerLineNumber)
{
Sequence = sequence;
MessageType = messageType;
UtcDate = utcDate;
Source = source;
Message = message;
CallerMemberName = callerMemberName;
CallerFilePath = callerFilePath;
CallerLineNumber = callerLineNumber;
ExtendedData = extendedData;
}
///
/// Gets logging message sequence.
///
///
/// The sequence.
///
public ulong Sequence { get; }
///
/// Gets the type of the message.
/// It can be a combination as the enumeration is a set of bitwise flags.
///
///
/// The type of the message.
///
public LogMessageType MessageType { get; }
///
/// Gets the UTC date at which the event at which the message was logged.
///
///
/// The UTC date.
///
public DateTime UtcDate { get; }
///
/// Gets the name of the source where the logging message
/// came from. This can come empty if the logger did not set it.
///
///
/// The source.
///
public string Source { get; }
///
/// Gets the body of the message.
///
///
/// The message.
///
public string Message { get; }
///
/// Gets the name of the caller member.
///
///
/// The name of the caller member.
///
public string CallerMemberName { get; }
///
/// Gets the caller file path.
///
///
/// The caller file path.
///
public string CallerFilePath { get; }
///
/// Gets the caller line number.
///
///
/// The caller line number.
///
public int CallerLineNumber { get; }
///
/// Gets an object representing extended data.
/// It could be an exception or anything else.
///
///
/// The extended data.
///
public object ExtendedData { get; }
///
/// Gets the Extended Data properties cast as an Exception (if possible)
/// Otherwise, it return null.
///
///
/// The exception.
///
public Exception Exception => ExtendedData as Exception;
}
///
/// Event arguments representing a message logged and about to be
/// displayed on the terminal (console). Set the CancelOutput property in the
/// event handler to prevent the terminal from displaying the message.
///
///
public class LogMessageDisplayingEventArgs : LogMessageReceivedEventArgs
{
///
/// Initializes a new instance of the class.
///
/// The instance containing the event data.
public LogMessageDisplayingEventArgs(LogMessageReceivedEventArgs data)
: base(
data.Sequence,
data.MessageType,
data.UtcDate,
data.Source,
data.Message,
data.ExtendedData,
data.CallerMemberName,
data.CallerFilePath,
data.CallerLineNumber)
{
CancelOutput = false;
}
///
/// Gets or sets a value indicating whether the displaying of the
/// logging message should be canceled.
///
///
/// true if [cancel output]; otherwise, false.
///
public bool CancelOutput { get; set; }
}
}