// Copyright 2003-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Apache.Avalon.Framework
{
using System;
using log4net;
///
/// The default log4net wrapper class for Logger.
///
public class Log4netLogger: ILogger
{
///
/// underlying implementation
///
private ILog m_logger;
///
/// Category name
///
private string m_name;
///
/// Creates a m_logger that delegates to specified category.
///
/// The ILog to delegate to.
/// The current category name.
public Log4netLogger(ILog logImpl, string name)
{
m_logger = logImpl;
m_name = name;
}
///
/// Logs a debug message.
///
/// The Message
public void Debug(string message )
{
m_logger.Debug(message);
}
///
/// Logs a debug message.
///
/// The Message
/// The Exception
public void Debug(string message, Exception exception)
{
m_logger.Debug( message, exception );
}
///
/// Logs a debug message.
///
/// Message format
/// Array of objects to write using format
public void Debug( string format, params Object[] args )
{
Debug(String.Format(format, args));
}
///
/// Determines if messages of priority "debug" will be logged.
///
/// True if "debug" messages will be logged.
public bool IsDebugEnabled
{
get
{
return m_logger.IsDebugEnabled;
}
}
///
/// Logs an info message.
///
/// The Message
public void Info( string message )
{
m_logger.Info(message);
}
///
/// Logs an info message.
///
/// The Message
/// The Exception
public void Info( string message, Exception exception)
{
m_logger.Info( message, exception);
}
///
/// Logs an info message.
///
/// Message format
/// Array of objects to write using format
public void Info( string format, params Object[] args )
{
Info(String.Format(format, args));
}
///
/// Determines if messages of priority "info" will be logged.
///
/// True if "info" messages will be logged.
public bool IsInfoEnabled
{
get
{
return m_logger.IsInfoEnabled;
}
}
///
/// Logs a warn message.
///
/// The Message
public void Warn(string message )
{
m_logger.Warn( message );
}
///
/// Logs a warn message.
///
/// The Message
/// The Exception
public void Warn(string message, Exception exception)
{
m_logger.Warn( message, exception );
}
///
/// Logs a warn message.
///
/// Message format
/// Array of objects to write using format
public void Warn( string format, params Object[] args )
{
Warn(String.Format(format, args));
}
///
/// Determines if messages of priority "warn" will be logged.
///
/// True if "warn" messages will be logged.
public bool IsWarnEnabled
{
get
{
return m_logger.IsWarnEnabled;
}
}
///
/// Logs an error message.
///
/// The Message
public void Error(string message )
{
m_logger.Error( message );
}
///
/// Logs an error message.
///
/// The Message
/// The Exception
public void Error(string message, Exception exception)
{
m_logger.Error( message, exception );
}
///
/// Logs an error message.
///
/// Message format
/// Array of objects to write using format
public void Error( string format, params Object[] args )
{
Error(String.Format(format, args));
}
///
/// Determines if messages of priority "error" will be logged.
///
/// True if "error" messages will be logged.
public bool IsErrorEnabled
{
get
{
return m_logger.IsErrorEnabled;
}
}
///
/// Logs a fatal error message.
///
/// The Message
public void FatalError(string message )
{
m_logger.Fatal( message );
}
///
/// Logs a fatal error message.
///
/// The Message
/// The Exception
public void FatalError(string message, Exception exception)
{
m_logger.Fatal( message, exception);
}
///
/// Logs a fatal error message.
///
/// Message format
/// Array of objects to write using format
public void FatalError( string format, params Object[] args )
{
FatalError(format, args);
}
///
/// Determines if messages of priority "fatalError" will be logged.
///
/// True if "fatalError" messages will be logged.
public bool IsFatalErrorEnabled
{
get
{
return m_logger.IsFatalEnabled;
}
}
///
/// Create a new child logger.
/// The name of the child logger is [current-loggers-name].[passed-in-name]
///
/// The Subname of this logger.
/// The New ILogger instance.
/// If the name has an empty element name.
public ILogger CreateChildLogger(string name )
{
string newName = m_name + "." + name;
return new Log4netLogger( LogManager.GetLogger( newName ), newName );
}
}
}