ymikulski 2002/08/13 05:59:11 Added: csframework/src/cs/Logger AbstractLogEnabled.cs ConsoleLogger.cs ILogEnabled.cs ILogger.cs Log4netLogger.cs NullLogger.cs Log: no message Revision Changes Path 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/AbstractLogEnabled.cs Index: AbstractLogEnabled.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; namespace Apache.Avalon.Logger { /// <summary> /// The Utility class to allow construction of easy components /// that will perform logging. /// </summary> public abstract class AbstractLogEnabled: ILogEnabled { // Base ILogger instance private ILogger logger; /// <summary> /// Gets the ILogger instance. /// </summary> protected ILogger Logger { get { return logger; } } /// <summary> /// The Method sets the component logger. /// </summary> /// <param name="logger">The ILogger instance.</param> public void EnableLogging(ILogger logger ) { this.logger = logger; } /// <summary> /// The Helper method to setup other components with same logger. /// </summary> /// <param name="component">The Component to pass logger object to.</param> protected void SetupLogger(object component) { SetupLogger( component, (string)null ); } /// <summary> /// The Helper method to setup other components with logger. /// The logger has the subcategory of this components logger. /// </summary> /// <param name="component">The Component to pass logger object to.</param> /// <param name="subCategory">The Subcategory to use.</param> protected void SetupLogger(object component, string subCategory ) { ILogger logger = Logger; if(subCategory != null) { logger = Logger.CreateChildLogger( subCategory ); } SetupLogger( component, logger ); } /// <summary> /// The Helper method to setup other components with logger. /// </summary> /// <param name="component">The Component to pass logger object to.</param> /// <param name="logger">The ILogger instance.</param> protected void SetupLogger(object component, ILogger logger ) { if( component is ILogEnabled ) { ((ILogEnabled) component).EnableLogging( logger ); } } } } 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/ConsoleLogger.cs Index: ConsoleLogger.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; namespace Apache.Avalon.Logger { /// <summary> /// The Logger sending everything to the standard output streams. /// This is mainly for the cases when you have a utility that /// does not have a logger to supply. /// </summary> public class ConsoleLogger: ILogger { /// <summary> /// Typecode for debugging messages. /// </summary> public const int LEVEL_DEBUG = 0; public const string LEVEL_DEBUG_NAME = "DEBUG"; /// <summary> /// Typecode for informational messages. /// </summary> public const int LEVEL_INFO = 1; public const string LEVEL_INFO_NAME = "INFO"; /// <summary> /// Typecode for warning messages. /// </summary> public const int LEVEL_WARN = 2; public const string LEVEL_WARN_NAME = "WARN"; /// <summary> /// Typecode for error messages. /// </summary> public const int LEVEL_ERROR = 3; public const string LEVEL_ERROR_NAME = "ERROR"; /// <summary> /// Typecode for fatal error messages. /// </summary> public const int LEVEL_FATAL = 4; public const string LEVEL_FATAL_NAME = "FATAL ERROR"; /// <summary> /// Typecode for disabled log levels. /// </summary> public const int LEVEL_DISABLED = 5; private int logLevel; /// <summary> /// Creates a new ConsoleLogger with the priority set to DEBUG. /// </summary> public ConsoleLogger(): this(LEVEL_DEBUG) { } /// <summary> /// Creates a new ConsoleLogger. /// </summary> /// <param name="logLevel">The Log level typecode.</param> public ConsoleLogger(int logLevel) { this.logLevel = logLevel; } /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> public void Debug(string message ) { Debug(message, null); } /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Debug(string message, Exception exception) { Log(ConsoleLogger.LEVEL_DEBUG, ConsoleLogger.LEVEL_DEBUG_NAME, message, exception); } /// <summary> /// Determines if messages of priority "debug" will be logged. /// </summary> /// <value>True if "debug" messages will be logged.</value> public bool IsDebugEnabled { get { return (logLevel <= LEVEL_DEBUG); } } /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> public void Info( string message ) { Info(message, null); } /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Info( string message, Exception exception) { Log(ConsoleLogger.LEVEL_INFO, ConsoleLogger.LEVEL_INFO_NAME, message, exception); } /// <summary> /// Determines if messages of priority "info" will be logged. /// </summary> /// <value>True if "info" messages will be logged.</value> public bool IsInfoEnabled { get { return (logLevel <= LEVEL_INFO); } } /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> public void Warn(string message ) { Warn(message, null); } /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Warn(string message, Exception exception) { Log(ConsoleLogger.LEVEL_WARN, ConsoleLogger.LEVEL_WARN_NAME, message, exception); } /// <summary> /// Determines if messages of priority "warn" will be logged. /// </summary> /// <value>True if "warn" messages will be logged.</value> public bool IsWarnEnabled { get { return (logLevel <= LEVEL_WARN); } } /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> public void Error(string message ) { Error(message, null); } /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Error(string message, Exception exception) { Log(ConsoleLogger.LEVEL_ERROR, ConsoleLogger.LEVEL_ERROR_NAME, message, exception); } /// <summary> /// Determines if messages of priority "error" will be logged. /// </summary> /// <value>True if "error" messages will be logged.</value> public bool IsErrorEnabled { get { return (logLevel <= LEVEL_ERROR); } } /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> public void FatalError(string message ) { FatalError(message, null); } /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void FatalError(string message, Exception exception) { Log(ConsoleLogger.LEVEL_FATAL, ConsoleLogger.LEVEL_FATAL_NAME, message, exception); } /// <summary> /// Determines if messages of priority "fatalError" will be logged. /// </summary> /// <value>True if "fatalError" messages will be logged.</value> public bool IsFatalErrorEnabled { get { return (logLevel <= LEVEL_FATAL); } } /// <summary> /// A Common method to log. /// </summary> /// <param name="level">The level of logging</param> /// <param name="levelName">The Level name</param> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> protected void Log(int level, string levelName, string message, Exception exception) { if(logLevel <= level) { Console.Out.WriteLine(string.Format("[{0}] {1}", levelName, message)); if(exception != null) { Console.Out.WriteLine(exception.StackTrace); } } } /// <summary> /// Just returns this logger (<c>ConsoleLogger</c> is not hierarchical). /// </summary> /// <param name="name">Ignored</param> /// <returns>This ILogger instance.</returns> public ILogger CreateChildLogger(string name ) { return this; } } } 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/ILogEnabled.cs Index: ILogEnabled.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; namespace Apache.Avalon.Logger { /// <summary> /// Components that need to log can implement this interface to /// be provided Loggers. /// </summary> public interface ILogEnabled { /// <summary> /// Provides a component with a logger. /// </summary> /// <param name="logger">The ILogger instance.</param> void EnableLogging(ILogger logger); } } 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/ILogger.cs Index: ILogger.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; namespace Apache.Avalon.Logger { /// <summary> /// This is a facade for the different logging subsystems. /// It offers a simplified interface that follows IOC patterns /// and a simplified priority/level/severity abstraction. /// </summary> public interface ILogger { /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> void Debug( string message ); /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> void Debug( string message, Exception exception); /// <summary> /// Determines if messages of priority "debug" will be logged. /// </summary> /// <value>True if "debug" messages will be logged.</value> bool IsDebugEnabled { get; } /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> void Info( string message ); /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> void Info( string message, Exception exception); /// <summary> /// Determines if messages of priority "info" will be logged. /// </summary> /// <value>True if "info" messages will be logged.</value> bool IsInfoEnabled { get; } /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> void Warn( string message ); /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> void Warn( string message, Exception exception); /// <summary> /// Determines if messages of priority "warn" will be logged. /// </summary> /// <value>True if "warn" messages will be logged.</value> bool IsWarnEnabled { get; } /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> void Error( string message ); /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> void Error( string message, Exception exception); /// <summary> /// Determines if messages of priority "error" will be logged. /// </summary> /// <value>True if "error" messages will be logged.</value> bool IsErrorEnabled { get; } /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> void FatalError( string message ); /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> void FatalError( string message, Exception exception); /// <summary> /// Determines if messages of priority "fatalError" will be logged. /// </summary> /// <value>True if "fatalError" messages will be logged.</value> bool IsFatalErrorEnabled { get; } /// <summary> /// Create a new child logger. /// The name of the child logger is [current-loggers-name].[passed-in-name] /// </summary> /// <param name="name">The Subname of this logger.</param> /// <returns>The New ILogger instance.</returns> /// <exception cref="System.ArgumentException">If the name has an empty element name.</exception> ILogger CreateChildLogger( string name ); } } 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/Log4netLogger.cs Index: Log4netLogger.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; using log4net; namespace Apache.Avalon.Logger { /// <summary> /// The default log4net wrapper class for Logger. /// </summary> public class Log4netLogger: ILogger { //underlying implementation private Category logger; /// <summary> /// Creates a logger that delegates to specified category. /// </summary> /// <param name="logImpl">The Category to delegate to.</param> public Log4netLogger(Category logImpl) { logger = logImpl; } /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> public void Debug(string message ) { logger.Debug(message); } /// <summary> /// Logs a debug message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Debug(string message, Exception exception) { logger.Debug( message, exception ); } /// <summary> /// Determines if messages of priority "debug" will be logged. /// </summary> /// <value>True if "debug" messages will be logged.</value> public bool IsDebugEnabled { get { return logger.IsDebugEnabled; } } /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> public void Info( string message ) { logger.Info(message); } /// <summary> /// Logs an info message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Info( string message, Exception exception) { logger.Info( message, exception); } /// <summary> /// Determines if messages of priority "info" will be logged. /// </summary> /// <value>True if "info" messages will be logged.</value> public bool IsInfoEnabled { get { return logger.IsInfoEnabled; } } /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> public void Warn(string message ) { logger.Warn( message ); } /// <summary> /// Logs a warn message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Warn(string message, Exception exception) { logger.Warn( message, exception ); } /// <summary> /// Determines if messages of priority "warn" will be logged. /// </summary> /// <value>True if "warn" messages will be logged.</value> public bool IsWarnEnabled { get { return logger.IsWarnEnabled; } } /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> public void Error(string message ) { logger.Error( message ); } /// <summary> /// Logs an error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void Error(string message, Exception exception) { logger.Error( message, exception ); } /// <summary> /// Determines if messages of priority "error" will be logged. /// </summary> /// <value>True if "error" messages will be logged.</value> public bool IsErrorEnabled { get { return logger.IsErrorEnabled; } } /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> public void FatalError(string message ) { logger.Fatal( message ); } /// <summary> /// Logs a fatal error message. /// </summary> /// <param name="message">The Message</param> /// <param name="exception">The Exception</param> public void FatalError(string message, Exception exception) { logger.Fatal( message, exception); } /// <summary> /// Determines if messages of priority "fatalError" will be logged. /// </summary> /// <value>True if "fatalError" messages will be logged.</value> public bool IsFatalErrorEnabled { get { return logger.IsFatalEnabled; } } /// <summary> /// Create a new child logger. /// The name of the child logger is [current-loggers-name].[passed-in-name] /// </summary> /// <param name="name">The Subname of this logger.</param> /// <returns>The New ILogger instance.</returns> /// <exception cref="System.ArgumentException">If the name has an empty element name.</exception> public ILogger CreateChildLogger(string name ) { return new Log4netLogger( Category.GetInstance( logger.Name + "." + name ) ); } } } 1.1 jakarta-avalon-excalibur/csframework/src/cs/Logger/NullLogger.cs Index: NullLogger.cs =================================================================== /// /// Copyright (C) The Apache Software Foundation. All rights reserved. /// /// This software is published under the terms of the Apache Software License /// version 1.1, a copy of which has been included with this distribution in /// the LICENSE.txt file. /// using System; namespace Apache.Avalon.Logger { /// <summary> /// The Null Logger class. This is useful for implementations where you need /// to provide a logger to a utility class, but do not want any output from it. /// It also helps when you have a utility that does not have a logger to supply. /// </summary> public class NullLogger: ILogger { /// <summary> /// Creates a new <c>NullLogger</c>. /// </summary> public NullLogger() { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> public void Debug(string message ) { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> /// <param name="exception">Ignored</param> public void Debug(string message, Exception exception) { } /// <summary> /// No-op. /// </summary> /// <value>false</value> public bool IsDebugEnabled { get { return false; } } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> public void Info( string message ) { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> /// <param name="exception">Ignored</param> public void Info( string message, Exception exception) { } /// <summary> /// No-op. /// </summary> /// <value>false</value> public bool IsInfoEnabled { get { return false; } } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> public void Warn(string message ) { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> /// <param name="exception">Ignored</param> public void Warn(string message, Exception exception) { } /// <summary> /// No-op. /// </summary> /// <value>false</value> public bool IsWarnEnabled { get { return false; } } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> public void Error(string message ) { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> /// <param name="exception">Ignored</param> public void Error(string message, Exception exception) { } /// <summary> /// No-op. /// </summary> /// <value>false</value> public bool IsErrorEnabled { get { return false; } } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> public void FatalError(string message ) { } /// <summary> /// No-op. /// </summary> /// <param name="message">Ignored</param> /// <param name="exception">Ignored</param> public void FatalError(string message, Exception exception) { } /// <summary> /// No-op. /// </summary> /// <value>false</value> public bool IsFatalErrorEnabled { get { return false; } } /// <summary> /// Returns this <c>NullLogger</c>. /// </summary> /// <param name="name">Ignored</param> /// <returns>This ILogger instance.</returns> public ILogger CreateChildLogger(string name ) { return this; } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>