#region S# License /****************************************************************************************** NOTICE!!! This program and source code is owned and licensed by StockSharp, LLC, www.stocksharp.com Viewing or use of this code requires your acceptance of the license agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE Removal of this comment is a violation of the license agreement. Project: StockSharp.Logging.Logging File: LogMessage.cs Created: 2015, 11, 11, 2:32 PM Copyright 2010 by StockSharp, LLC *******************************************************************************************/ #endregion S# License namespace StockSharp.Logging { using System; using Ecng.Common; /// /// A debug message. /// public class LogMessage { internal bool IsDispose; private Func _getMessage; /// /// Initializes a new instance of the . /// /// The log source. /// Message creating time. /// The level of the log message. /// Text message. /// Text message settings. Used if a message is the format string. For details, see . public LogMessage(ILogSource source, DateTimeOffset time, LogLevels level, string message, params object[] args) : this(source, time, level, () => message.Put(args)) { } /// /// Initializes a new instance of the . /// /// The log source. /// Message creating time. /// The level of the log message. /// The function returns the text for . public LogMessage(ILogSource source, DateTimeOffset time, LogLevels level, Func getMessage) { if (source == null) throw new ArgumentNullException(nameof(source)); if (getMessage == null) throw new ArgumentNullException(nameof(getMessage)); _getMessage = getMessage; Source = source; Time = time; Level = level; } /// /// The log source. /// public ILogSource Source { get; } /// /// Message creating time. /// public DateTimeOffset Time { get; set; } /// /// The level of the log message. /// public LogLevels Level { get; } private string _message; /// /// Message. /// public string Message { get { if (_message != null) return _message; try { _message = _getMessage(); } catch (Exception ex) { _message = ex.ToString(); } // делегат может захватить из внешнего кода лишние данные, что не будут удаляться GC // в случае, если LogMessage будет храниться где-то (например, в LogControl) _getMessage = null; return _message; } } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. public override string ToString() { return "{0} {1}".Put(Time, Message); } } }