/// <summary> /// To record a message to the log. /// </summary> /// <param name="receiver">Logs receiver.</param> /// <param name="level">The level of the log message.</param> /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param> public static void AddLog(this ILogReceiver receiver, LogLevels level, Func<string> getMessage) { if (receiver == null) throw new ArgumentNullException(nameof(receiver)); receiver.AddLog(new LogMessage(receiver, receiver.CurrentTime, level, getMessage)); }
/// <summary> /// To record an error to the log. /// </summary> /// <param name="receiver">Logs receiver.</param> /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param> public static void AddErrorLog(this ILogReceiver receiver, Func<string> getMessage) { receiver.AddLog(LogLevels.Error, getMessage); }
/// <summary> /// To record a warning to the log. /// </summary> /// <param name="receiver">Logs receiver.</param> /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param> public static void AddWarningLog(this ILogReceiver receiver, Func<string> getMessage) { receiver.AddLog(LogLevels.Warning, getMessage); }
/// <summary> /// To record a message to the log. /// </summary> /// <param name="receiver">Logs receiver.</param> /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param> public static void AddInfoLog(this ILogReceiver receiver, Func<string> getMessage) { receiver.AddLog(LogLevels.Info, getMessage); }
private static void AddMessage(this ILogReceiver receiver, LogLevels level, string message, params object[] args) { if (receiver == null) throw new ArgumentNullException(nameof(receiver)); if (level < receiver.LogLevel) return; receiver.AddLog(new LogMessage(receiver, receiver.CurrentTime, level, message, args)); }
/// <summary> /// To record an error to the log. /// </summary> /// <param name="receiver">Logs receiver.</param> /// <param name="exception">Error detais.</param> /// <param name="message">Text message.</param> public static void AddErrorLog(this ILogReceiver receiver, Exception exception, string message) { if (receiver == null) throw new ArgumentNullException(nameof(receiver)); if (exception == null) throw new ArgumentNullException(nameof(exception)); receiver.AddLog(new LogMessage(receiver, receiver.CurrentTime, LogLevels.Error, () => { var msg = exception.ToString(); var refExc = exception as ReflectionTypeLoadException; if (refExc != null) { msg += Environment.NewLine + refExc .LoaderExceptions .Select(e => e.ToString()) .Join(Environment.NewLine); } if (message != null) msg = message.Put(msg); return msg; })); }