JD2022-TU1/main/tools/framework/JD.LogService/Message.cs

88 lines
2.1 KiB
C#

using System;
using JD.Kernel.Structs;
namespace JD.LogService
{
/// <summary>
/// An informational message.
/// </summary>
[Serializable]
public class Message : LogEvent
{
#region Variables
private MessageImportance m_importance = MessageImportance.Normal;
#endregion
#region Constructors
public Message()
: base(LogCategory.Message)
{}
public Message(string message)
: this()
{
Message = message;
}
public Message(string message, params object[] args)
: this(FormatString(message, args))
{
}
[Obsolete("Log events are now mutable. Use the basic Message(string) constructor and set the rest of the properties.")] // 2011.01
public Message(FileLocation origin, string message)
: this(message)
{
Origin = origin;
}
#endregion
#region Properties
/// <summary>
/// Relative importance of the message.
/// </summary>
public MessageImportance Importance
{
get { return m_importance; }
set { m_importance = value; }
}
#endregion
#region Methods
public override string ToString()
{
return $"[Message: Text={Message}, Importance={Importance}]";
}
/// <summary>
/// Returns the message in canonical format.
/// </summary>
public override string ToCanonicalString()
{
if (m_importance != MessageImportance.Normal)
{
return $"{m_importance}:{Message}";
}
return Message;
}
#endregion
#region Static Creation
[Obsolete("Log events are now mutable. Use the basic Message(string, object[]) constructor.")] // 2011.01
public static Message MessageFormated(string message, params object[] args)
{
return new Message(message, args);
}
#endregion
}
}