Skip to content

Instantly share code, notes, and snippets.

@danielmarbach
Created May 2, 2010 20:36
Show Gist options
  • Save danielmarbach/387423 to your computer and use it in GitHub Desktop.
Save danielmarbach/387423 to your computer and use it in GitHub Desktop.
/// <summary>
/// Component logger which allows to log component outputs.
/// </summary>
public class ComponentLogger : ILog, IInitializable
{
private static readonly IDictionary<string, IEnumerable<IAppender>> ComponentAppender = new Dictionary<string, IEnumerable<IAppender>>();
private readonly IComponentLoggerAppenderFactory appenderFactory;
private readonly IComponentLoggerContext context;
private readonly string loggerName;
private ILog logger;
/// <summary>
/// Initializes a new instance of the <see cref="ComponentLogger"/> class.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="loggerName">Name of the logger.</param>
/// <param name="appenderFactory">The appender factory.</param>
public ComponentLogger(IComponentLoggerContext context, string loggerName, IComponentLoggerAppenderFactory appenderFactory)
{
this.loggerName = loggerName;
this.context = context;
this.appenderFactory = appenderFactory;
}
/// <summary>
/// Gets the implementation behind this wrapper object.
/// </summary>
/// <value>
/// The <see cref="T:log4net.Core.ILogger"/> object that in implementing this object.
/// </value>
/// <remarks>
/// The <see cref="T:log4net.Core.ILogger"/> object that in implementing this
/// object. The <c>Logger</c> object may not
/// be the same object as this object because of logger decorators.
/// This gets the actual underlying objects that is used to process
/// the log events.
/// </remarks>
public ILogger Logger
{
get { return this.logger.Logger; }
}
/// <summary>
/// Gets a value indicating whether this logger is enabled for the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <value>
/// <c>true</c> if this logger is enabled for <see cref="F:log4net.Core.Level.Debug"/> events, <c>false</c> otherwise.
/// </value>
/// <remarks>
/// <para>
/// This function is intended to lessen the computational cost of
/// disabled log debug statements.
/// </para>
/// <para> For some ILog interface <c>log</c>, when you write:</para>
/// <code lang="C#">
/// log.Debug("This is entry number: " + i );
/// </code>
/// <para>
/// You incur the cost constructing the message, string construction and concatenation in
/// this case, regardless of whether the message is logged or not.
/// </para>
/// <para>
/// If you are worried about speed (who isn't), then you should write:
/// </para>
/// <code lang="C#">
/// if (log.IsDebugEnabled)
/// {
/// log.Debug("This is entry number: " + i );
/// }
/// </code>
/// <para>
/// This way you will not incur the cost of parameter
/// construction if debugging is disabled for <c>log</c>. On
/// the other hand, if the <c>log</c> is debug enabled, you
/// will incur the cost of evaluating whether the logger is debug
/// enabled twice. Once in <see cref="P:log4net.ILog.IsDebugEnabled"/> and once in
/// the <see cref="M:log4net.ILog.Debug(System.Object)"/>. This is an insignificant overhead
/// since evaluating a logger takes about 1% of the time it
/// takes to actually log. This is the preferred style of logging.
/// </para>
/// <para>Alternatively if your logger is available statically then the is debug
/// enabled state can be stored in a static variable like this:
/// </para>
/// <code lang="C#">
/// private static readonly bool isDebugEnabled = log.IsDebugEnabled;
/// </code>
/// <para>
/// Then when you come to log you can write:
/// </para>
/// <code lang="C#">
/// if (isDebugEnabled)
/// {
/// log.Debug("This is entry number: " + i );
/// }
/// </code>
/// <para>
/// This way the debug enabled state is only queried once
/// when the class is loaded. Using a <c>private static readonly</c>
/// variable is the most efficient because it is a run time constant
/// and can be heavily optimized by the JIT compiler.
/// </para>
/// <para>
/// Of course if you use a static readonly variable to
/// hold the enabled state of the logger then you cannot
/// change the enabled state at runtime to vary the logging
/// that is produced. You have to decide if you need absolute
/// speed or runtime flexibility.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="M:log4net.ILog.DebugFormat(System.IFormatProvider,System.String,System.Object[])"/>
public bool IsDebugEnabled
{
get { return this.logger.IsDebugEnabled; }
}
/// <summary>
/// Gets a value indicating whether this logger is enabled for the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <value>
/// <c>true</c> if this logger is enabled for <see cref="F:log4net.Core.Level.Info"/> events, <c>false</c> otherwise.
/// </value>
/// <remarks>
/// For more information see <see cref="P:log4net.ILog.IsDebugEnabled"/>.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object)"/>
/// <seealso cref="M:log4net.ILog.InfoFormat(System.IFormatProvider,System.String,System.Object[])"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public bool IsInfoEnabled
{
get { return this.logger.IsInfoEnabled; }
}
/// <summary>
/// Gets a value indicating whether this logger is enabled for the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <value>
/// <c>true</c> if this logger is enabled for <see cref="F:log4net.Core.Level.Warn"/> events, <c>false</c> otherwise.
/// </value>
/// <remarks>
/// For more information see <see cref="P:log4net.ILog.IsDebugEnabled"/>.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object)"/>
/// <seealso cref="M:log4net.ILog.WarnFormat(System.IFormatProvider,System.String,System.Object[])"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public bool IsWarnEnabled
{
get { return this.logger.IsWarnEnabled; }
}
/// <summary>
/// Gets a value indicating whether this logger is enabled for the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <value>
/// <c>true</c> if this logger is enabled for <see cref="F:log4net.Core.Level.Error"/> events, <c>false</c> otherwise.
/// </value>
/// <remarks>
/// For more information see <see cref="P:log4net.ILog.IsDebugEnabled"/>.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object)"/>
/// <seealso cref="M:log4net.ILog.ErrorFormat(System.IFormatProvider,System.String,System.Object[])"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public bool IsErrorEnabled
{
get { return this.logger.IsErrorEnabled; }
}
/// <summary>
/// Gets a value indicating whether this logger is enabled for the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <value>
/// <c>true</c> if this logger is enabled for <see cref="F:log4net.Core.Level.Fatal"/> events, <c>false</c> otherwise.
/// </value>
/// <remarks>
/// For more information see <see cref="P:log4net.ILog.IsDebugEnabled"/>.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object)"/>
/// <seealso cref="M:log4net.ILog.FatalFormat(System.IFormatProvider,System.String,System.Object[])"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public bool IsFatalEnabled
{
get { return this.logger.IsFatalEnabled; }
}
/// <summary>
/// Gets the hierarchy.
/// </summary>
/// <returns>The hierarchy.</returns>
protected virtual ILoggerRepository Hierarchy
{
get
{
return LogManager.GetRepository();
}
}
/// <summary>
/// Initializes the current instance.
/// </summary>
public void Initialize()
{
lock (ComponentAppender)
{
ILoggerRepository hierarchy = this.Hierarchy;
hierarchy.Configured = false;
if (!ComponentAppender.ContainsKey(this.context.ComponentName))
{
var appenders = this.appenderFactory.CreateAppender(this.context);
ComponentAppender.Add(this.context.ComponentName, appenders);
}
string name = string.Format(CultureInfo.InvariantCulture, "{1} [{0}]", this.context.ComponentName, this.loggerName);
Logger log = this.GetLoggerFromHierarchy(hierarchy, name);
ComponentAppender[this.context.ComponentName].ToList().ForEach(log.AddAppender);
hierarchy.Configured = true;
this.logger = this.GetLoggerByName(name);
}
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <overloads>Log a message object with the <see cref="F:log4net.Core.Level.Debug"/> level.</overloads>
/// <remarks>
/// <para>
/// This method first checks if this logger is <c>DEBUG</c>
/// enabled by comparing the level of this logger with the
/// <see cref="F:log4net.Core.Level.Debug"/> level. If this logger is
/// <c>DEBUG</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
/// <see cref="T:log4net.ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of
/// the additivity flag.
/// </para>
/// <para><b>WARNING</b> Note that passing an <see cref="T:System.Exception"/>
/// to this method will print the name of the <see cref="T:System.Exception"/>
/// but no stack trace. To print a stack trace use the
/// <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/> form instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void Debug(object message)
{
this.logger.Debug(message);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Debug"/> level including
/// the stack trace of the <see cref="T:System.Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// See the <see cref="M:log4net.ILog.Debug(System.Object)"/> form for more detailed information.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void Debug(object message, Exception exception)
{
this.logger.Debug(message, exception);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <overloads>Log a formatted string with the <see cref="F:log4net.Core.Level.Debug"/> level.</overloads>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "log4net.ILog.DebugFormat(System.String,System.Object[])", Justification = "Wrapper to log4net")]
public void DebugFormat(string format, params object[] args)
{
this.logger.DebugFormat(format, args);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void DebugFormat(string format, object arg0)
{
this.logger.DebugFormat(format, arg0);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void DebugFormat(string format, object arg0, object arg1)
{
this.logger.DebugFormat(format, arg0, arg1);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <param name="arg2">An Object arg2 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void DebugFormat(string format, object arg0, object arg1, object arg2)
{
this.logger.DebugFormat(format, arg0, arg1, arg2);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Debug"/> level.
/// </summary>
/// <param name="provider">An <see cref="T:System.IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Debug(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Debug(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsDebugEnabled"/>
public void DebugFormat(IFormatProvider provider, string format, params object[] args)
{
this.logger.DebugFormat(provider, format, args);
}
/// <summary>
/// Logs a message object with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <overloads>Log a message object with the <see cref="F:log4net.Core.Level.Info"/> level.</overloads>
/// <remarks>
/// <para>
/// This method first checks if this logger is <c>INFO</c>
/// enabled by comparing the level of this logger with the
/// <see cref="F:log4net.Core.Level.Info"/> level. If this logger is
/// <c>INFO</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
/// <see cref="T:log4net.ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of the
/// additivity flag.
/// </para>
/// <para><b>WARNING</b> Note that passing an <see cref="T:System.Exception"/>
/// to this method will print the name of the <see cref="T:System.Exception"/>
/// but no stack trace. To print a stack trace use the
/// <see cref="M:log4net.ILog.Info(System.Object,System.Exception)"/> form instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void Info(object message)
{
this.logger.Info(message);
}
/// <summary>
/// Logs a message object with the <c>INFO</c> level including
/// the stack trace of the <see cref="T:System.Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// See the <see cref="M:log4net.ILog.Info(System.Object)"/> form for more detailed information.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void Info(object message, Exception exception)
{
this.logger.Info(message, exception);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <overloads>Log a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.</overloads>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Info(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "log4net.ILog.InfoFormat(System.String,System.Object[])", Justification = "Wrapper to log4net")]
public void InfoFormat(string format, params object[] args)
{
this.logger.InfoFormat(format, args);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void InfoFormat(string format, object arg0)
{
this.logger.InfoFormat(format, arg0);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void InfoFormat(string format, object arg0, object arg1)
{
this.logger.InfoFormat(format, arg0, arg1);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <param name="arg2">An Object arg2 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void InfoFormat(string format, object arg0, object arg1, object arg2)
{
this.logger.InfoFormat(format, arg0, arg1, arg2);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Info"/> level.
/// </summary>
/// <param name="provider">An <see cref="T:System.IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Info(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Info(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsInfoEnabled"/>
public void InfoFormat(IFormatProvider provider, string format, params object[] args)
{
this.logger.InfoFormat(provider, format, args);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <overloads>Log a message object with the <see cref="F:log4net.Core.Level.Warn"/> level.</overloads>
/// <remarks>
/// <para>
/// This method first checks if this logger is <c>WARN</c>
/// enabled by comparing the level of this logger with the
/// <see cref="F:log4net.Core.Level.Warn"/> level. If this logger is
/// <c>WARN</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
/// <see cref="T:log4net.ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of the
/// additivity flag.
/// </para>
/// <para><b>WARNING</b> Note that passing an <see cref="T:System.Exception"/>
/// to this method will print the name of the <see cref="T:System.Exception"/>
/// but no stack trace. To print a stack trace use the
/// <see cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/> form instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void Warn(object message)
{
this.logger.Warn(message);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Warn"/> level including
/// the stack trace of the <see cref="T:System.Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// See the <see cref="M:log4net.ILog.Warn(System.Object)"/> form for more detailed information.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void Warn(object message, Exception exception)
{
this.logger.Warn(message, exception);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <overloads>Log a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.</overloads>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Warn(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "log4net.ILog.WarnFormat(System.String,System.Object[])", Justification = "Wrapper to log4net")]
public void WarnFormat(string format, params object[] args)
{
this.logger.WarnFormat(format, args);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void WarnFormat(string format, object arg0)
{
this.logger.WarnFormat(format, arg0);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void WarnFormat(string format, object arg0, object arg1)
{
this.logger.WarnFormat(format, arg0, arg1);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <param name="arg2">An Object arg2 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void WarnFormat(string format, object arg0, object arg1, object arg2)
{
this.logger.WarnFormat(format, arg0, arg1, arg2);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Warn"/> level.
/// </summary>
/// <param name="provider">An <see cref="T:System.IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Warn(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Warn(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsWarnEnabled"/>
public void WarnFormat(IFormatProvider provider, string format, params object[] args)
{
this.logger.WarnFormat(provider, format, args);
}
/// <summary>
/// Logs a message object with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <overloads>Log a message object with the <see cref="F:log4net.Core.Level.Error"/> level.</overloads>
/// <remarks>
/// <para>
/// This method first checks if this logger is <c>ERROR</c>
/// enabled by comparing the level of this logger with the
/// <see cref="F:log4net.Core.Level.Error"/> level. If this logger is
/// <c>ERROR</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
/// <see cref="T:log4net.ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of the
/// additivity flag.
/// </para>
/// <para><b>WARNING</b> Note that passing an <see cref="T:System.Exception"/>
/// to this method will print the name of the <see cref="T:System.Exception"/>
/// but no stack trace. To print a stack trace use the
/// <see cref="M:log4net.ILog.Error(System.Object,System.Exception)"/> form instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void Error(object message)
{
this.logger.Error(message);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Error"/> level including
/// the stack trace of the <see cref="T:System.Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// See the <see cref="M:log4net.ILog.Error(System.Object)"/> form for more detailed information.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void Error(object message, Exception exception)
{
this.logger.Error(message, exception);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <overloads>Log a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.</overloads>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Error(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "log4net.ILog.ErrorFormat(System.String,System.Object[])", Justification = "Wrapper to log4net")]
public void ErrorFormat(string format, params object[] args)
{
this.logger.ErrorFormat(format, args);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void ErrorFormat(string format, object arg0)
{
this.logger.ErrorFormat(format, arg0);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void ErrorFormat(string format, object arg0, object arg1)
{
this.logger.ErrorFormat(format, arg0, arg1);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <param name="arg2">An Object arg2 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void ErrorFormat(string format, object arg0, object arg1, object arg2)
{
this.logger.ErrorFormat(format, arg0, arg1, arg2);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Error"/> level.
/// </summary>
/// <param name="provider">An <see cref="T:System.IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Error(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Error(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsErrorEnabled"/>
public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
{
this.logger.ErrorFormat(provider, format, args);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <overloads>Log a message object with the <see cref="F:log4net.Core.Level.Fatal"/> level.</overloads>
/// <remarks>
/// <para>
/// This method first checks if this logger is <c>FATAL</c>
/// enabled by comparing the level of this logger with the
/// <see cref="F:log4net.Core.Level.Fatal"/> level. If this logger is
/// <c>FATAL</c> enabled, then it converts the message object
/// (passed as parameter) to a string by invoking the appropriate
/// <see cref="T:log4net.ObjectRenderer.IObjectRenderer"/>. It then
/// proceeds to call all the registered appenders in this logger
/// and also higher in the hierarchy depending on the value of the
/// additivity flag.
/// </para>
/// <para><b>WARNING</b> Note that passing an <see cref="T:System.Exception"/>
/// to this method will print the name of the <see cref="T:System.Exception"/>
/// but no stack trace. To print a stack trace use the
/// <see cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/> form instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void Fatal(object message)
{
this.logger.Fatal(message);
}
/// <summary>
/// Log a message object with the <see cref="F:log4net.Core.Level.Fatal"/> level including
/// the stack trace of the <see cref="T:System.Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
/// <remarks>
/// See the <see cref="M:log4net.ILog.Fatal(System.Object)"/> form for more detailed information.
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void Fatal(object message, Exception exception)
{
this.logger.Fatal(message, exception);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <overloads>Log a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.</overloads>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Fatal(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "log4net.ILog.FatalFormat(System.String,System.Object[])", Justification = "Wrapper to log4net")]
public void FatalFormat(string format, params object[] args)
{
this.logger.FatalFormat(format, args);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void FatalFormat(string format, object arg0)
{
this.logger.FatalFormat(format, arg0);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void FatalFormat(string format, object arg0, object arg1)
{
this.logger.FatalFormat(format, arg0, arg1);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="arg0">An Object arg0 to format</param>
/// <param name="arg1">An Object arg1 to format</param>
/// <param name="arg2">An Object arg2 to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void FatalFormat(string format, object arg0, object arg1, object arg2)
{
this.logger.FatalFormat(format, arg0, arg1, arg2);
}
/// <summary>
/// Logs a formatted message string with the <see cref="F:log4net.Core.Level.Fatal"/> level.
/// </summary>
/// <param name="provider">An <see cref="T:System.IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
/// <remarks>
/// <para>
/// The message is formatted using the <c>String.Format</c> method. See
/// <see cref="M:System.String.Format(System.String,System.Object[])"/> for details of the syntax of the format string and the behavior
/// of the formatting.
/// </para>
/// <para>
/// This method does not take an <see cref="T:System.Exception"/> object to include in the
/// log event. To pass an <see cref="T:System.Exception"/> use one of the <see cref="M:log4net.ILog.Fatal(System.Object)"/>
/// methods instead.
/// </para>
/// </remarks>
/// <seealso cref="M:log4net.ILog.Fatal(System.Object,System.Exception)"/>
/// <seealso cref="P:log4net.ILog.IsFatalEnabled"/>
public void FatalFormat(IFormatProvider provider, string format, params object[] args)
{
this.logger.FatalFormat(provider, format, args);
}
/// <summary>
/// Gets the logger from the hierarchy.
/// </summary>
/// <param name="hierarchy">The hierarchy.</param>
/// <param name="name">The name of the logger.</param>
/// <returns>The logger from the hierarchy.</returns>
protected virtual Logger GetLoggerFromHierarchy(ILoggerRepository hierarchy, string name)
{
return (Logger) hierarchy.GetLogger(name);
}
/// <summary>
/// Gets the name of the logger by the specified name.
/// </summary>
/// <param name="name">The name of the logger.</param>
/// <returns>The logger.</returns>
protected virtual ILog GetLoggerByName(string name)
{
return LogManager.GetLogger(name);
}
}
/// <summary>
/// Factory which helps to create the necessary appenders for the <see cref="ComponentLogger"/>.
/// </summary>
public class ComponentLoggerAppenderFactory : IComponentLoggerAppenderFactory
{
/// <summary>
/// Creates the appenders and activates them.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>A enumerable of appenders.</returns>
public IEnumerable<IAppender> CreateAppender(IComponentLoggerContext context)
{
var patternLayout = new PatternLayout
{
ConversionPattern =
"%date|%thread|%level|%logger|%message %exception[EOL]%newline"
};
patternLayout.ActivateOptions();
var appenders = new List<AppenderSkeleton>
{
new RollingFileAppender
{
File =
string.Format(
CultureInfo.InvariantCulture,
@"Log\Machines\Machines-{0}.log",
context.ComponentName),
AppendToFile = false,
Layout = patternLayout,
LockingModel = new FileAppender.MinimalLock(),
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxSizeRollBackups = 100,
MaximumFileSize = "25MB",
StaticLogFileName = true,
},
};
appenders.ForEach(appender => appender.ActivateOptions());
return appenders.OfType<IAppender>();
}
}
/// <summary>
/// Context implementation which is passed to the <see cref="ComponentLogger"/>.
/// </summary>
public class ComponentLoggerContext : IComponentLoggerContext
{
/// <summary>
/// Initializes a new instance of the <see cref="ComponentLoggerContext"/> class.
/// </summary>
/// <param name="identification">The identification.</param>
/// <param name="classification">The classification.</param>
/// <param name="componentName">Name of the component.</param>
public ComponentLoggerContext(Guid identification, Guid classification, string componentName)
{
this.Identification = identification;
this.Classification = classification;
this.ComponentName = componentName;
}
/// <summary>
/// Gets or sets the identification.
/// </summary>
/// <value>The identification.</value>
/// <remarks>The identification must be unique throughout the system.</remarks>
public Guid Identification
{
get;
set;
}
/// <summary>
/// Gets or sets the classification.
/// </summary>
/// <value>The classification.</value>
public Guid Classification
{
get;
set;
}
/// <summary>
/// Gets or sets the name of the component.
/// </summary>
/// <value>The name of the component.</value>
public string ComponentName
{
get;
set;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return this.ShallowDumpToString(CultureInfo.InvariantCulture);
}
}
/// <summary>
/// Factory which is responsible for creating appenders.
/// </summary>
public interface IComponentLoggerAppenderFactory
{
/// <summary>
/// Creates the appenders and activates them.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>A enumerable of appenders.</returns>
IEnumerable<IAppender> CreateAppender(IComponentLoggerContext context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment