/// <summary> /// Logs a warn message /// </summary> /// <param name="format">The format.</param> /// <param name="args">The args.</param> protected void Warn(string format, params object[] args) { var ssf = new SystemStringFormat(CultureInfo.InvariantCulture, format, args); if (log.IsWarnEnabled) { log.Logger.Log(GetType(), Level.Warn, ssf, null); } OnWarn(this, new MessageEventArgs(ssf.ToString())); }
public void StringFormat() { var layout = new LogMessageLayout(); var message = new SystemStringFormat(CultureInfo.CurrentCulture, "This is a {0}", "test"); var loggingEvent = GetLogginEvent(message); var result = GetMessage(layout, loggingEvent); Assert.AreEqual(message.ToString(), result.Message); }
/// <summary> /// Logs an error message /// </summary> /// <param name="exception">The exception.</param> /// <param name="format">The format.</param> /// <param name="args">The args.</param> protected void Error(Exception exception, string format, params object[] args) { SystemStringFormat message = new SystemStringFormat(CultureInfo.InvariantCulture, format, args); string errorMessage; if (exception != null) errorMessage = string.Format("{0}: {1}", message, exception.Message); else errorMessage = message.ToString(); errors.Add(new FdoETLException(errorMessage, exception)); OnError(this, new MessageEventArgs(message.ToString())); }
/// <summary> /// Logs an error message /// </summary> /// <param name="exception">The exception.</param> /// <param name="format">The format.</param> /// <param name="args">The args.</param> protected void Error(Exception exception, string format, params object[] args) { SystemStringFormat message = new SystemStringFormat(CultureInfo.InvariantCulture, format, args); string errorMessage; if(exception!=null) errorMessage = string.Format("{0}: {1}", message, exception.Message); else errorMessage = message.ToString(); errors.Add(new RhinoEtlException(errorMessage, exception)); if (log.IsErrorEnabled) { log.Logger.Log(GetType(), Level.Error, message, exception); } }
/// <summary> /// Logs a notice message /// </summary> /// <param name="format">The format.</param> /// <param name="args">The args.</param> protected void Notice(string format, params object[] args) { var ssf = new SystemStringFormat(CultureInfo.InvariantCulture, format, args); if (log.Logger.IsEnabledFor(Level.Notice)) { log.Logger.Log(GetType(), Level.Notice, ssf, null); } OnNotice(this, new MessageEventArgs(ssf.ToString())); }
public void When_object_is_from_log4net_should_call_to_string() { var log4NetObj = new SystemStringFormat(CultureInfo.InvariantCulture, "should see {0}", "this string"); string message = RenderObjectToString(log4NetObj); message.Should().Be("should see this string"); }
/// <summary> /// Logs a formatted message string with the specified <see cref="Level"/>. /// </summary> private static void LogMessage(Level level, string format, params object[] args) { var logger = GetLoggerInstance(); if (logger.IsEnabledFor(level)) { var message = new SystemStringFormat(CultureInfo.InvariantCulture, format, args); logger.Log(typeof(Log), level, message, null); } }