// -------------------------------- // // // Any authorized distribution of any copy of this code (including any related // documentation) must reproduce the following restrictions, disclaimer and copyright // notice: // The Genesys Name, trademarks and/or logo(s) of Genesys shall not be used to Name // (even as a part of another Name), endorse and/or promote products derived from // this code without prior written permission from Genesys Telecommunications // Laboratories, Inc. // // The use, copy, and/or distribution of this code is subject to the terms of the Genesys // Developer License Agreement. This code shall not be used, copied, and/or // distributed under any other license agreement. // THIS CODE IS PROVIDED BY GENESYS TELECOMMUNICATIONS LABORATORIES, INC. // (\'GENESYS\') 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND. GENESYS HEREBY // DISCLAIMS ALL EXPRESS, IMPLIED, OR STATUTORY CONDITIONS, REPRESENTATIONS AND // WARRANTIES WITH RESPECT TO THIS CODE (OR ANY PART THEREOF), INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE OR NON-INFRINGEMENT. GENESYS AND ITS SUPPLIERS SHALL // NOT BE LIABLE FOR ANY DAMAGE SUFFERED AS A RESULT OF USING THIS CODE. IN NO // EVENT SHALL GENESYS AND ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, // CONSEQUENTIAL, ECONOMIC, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING, BUT // NOT LIMITED TO, ANY LOST REVENUES OR PROFITS). // Copyright (c) 2008-2009 Genesys Telecommunications Laboratories, Inc. All Rights Reserved. // // // --------------------------------- namespace YourNamespace { using System; using System.Diagnostics; using Genesyslab.Platform.Commons.Logging; /// /// This is the default implementation of the Logger that sends messages to debug output stream /// public class TraceLogger: ILogger { /// /// Typecode for debugging messages. /// public const int LevelDebug = 0; /// /// String Name for debug level messages. /// public const string LevelDebugName = "DEBUG"; /// /// Typecode for informational messages. /// public const int LevelInfo = 1; /// /// String Name for info level messages. /// public const string LevelInfoName = "INFO"; /// /// Typecode for warning messages. /// public const int LevelWarn = 2; /// /// String Name for warn level messages. /// public const string LevelWarnName = "WARN"; /// /// Typecode for error messages. /// public const int LevelError = 3; /// /// String Name for error level messages. /// public const string LevelErrorName = "ERROR"; /// /// Typecode for fatal error messages. /// public const int LevelFatal = 4; /// /// String Name for fatal error level messages. /// public const string LevelFatalName = "FATAL ERROR"; /// /// Typecode for disabled log levels. /// public const int LevelDisabled = 5; private int logLevel; /// /// Creates a new TraceLogger with the priority set to DEBUG. /// public TraceLogger(): this(LevelDebug) { } /// /// Creates a new TraceLogger. /// /// The Log level typecode. public TraceLogger(int logLevel) { this.logLevel = logLevel; } /// /// Logs a debug message. /// /// The Message public void Debug(object message) { Debug(message, null as Exception); } /// /// Logs a debug message. /// /// The Message /// The Exception public void Debug(object message, Exception exception) { Log(TraceLogger.LevelDebug, TraceLogger.LevelDebugName, message, exception); } /// /// Logs a debug message. /// /// Message format /// Array of objects to write using format public void DebugFormat( 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 (logLevel <= LevelDebug); } } /// /// Logs an info message. /// /// The Message public void Info( object message ) { Info(message, null as Exception); } /// /// Logs an info message. /// /// The Message /// The Exception public void Info( object message, Exception exception) { Log(TraceLogger.LevelInfo, TraceLogger.LevelInfoName, message, exception); } /// /// Logs an info message. /// /// Message format /// Array of objects to write using format public void InfoFormat( 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 (logLevel <= LevelInfo); } } /// /// Logs a warn message. /// /// The Message public void Warn(object message ) { Warn(message, null as Exception); } /// /// Logs a warn message. /// /// The Message /// The Exception public void Warn(object message, Exception exception) { Log(TraceLogger.LevelWarn, TraceLogger.LevelWarnName, message, exception); } /// /// Logs an warn message. /// /// Message format /// Array of objects to write using format public void WarnFormat( 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 (logLevel <= LevelWarn); } } /// /// Logs an error message. /// /// The Message public void Error(object message ) { Error(message, null as Exception); } /// /// Logs an error message. /// /// The Message /// The Exception public void Error(object message, Exception exception) { Log(TraceLogger.LevelError, TraceLogger.LevelErrorName, message, exception); } /// /// Logs an error message. /// /// Message format /// Array of objects to write using format public void ErrorFormat( 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 (logLevel <= LevelError); } } /// /// Logs a fatal error message. /// /// The Message public void FatalError(object message ) { FatalError(message, null as Exception); } /// /// Logs a fatal error message. /// /// The Message /// The Exception public void FatalError(object message, Exception exception) { Log(TraceLogger.LevelFatal, TraceLogger.LevelFatalName, message, exception); } /// /// Logs a fatal error message. /// /// Message format /// Array of objects to write using format public void FatalErrorFormat( string format, params Object[] args ) { FatalError(String.Format(format, args)); } /// /// Determines if messages of priority "fatalError" will be logged. /// /// True if "fatalError" messages will be logged. public bool IsFatalErrorEnabled { get { return (logLevel <= LevelFatal); } } /// /// A Common method to log. /// /// The level of logging /// The Level Name /// The Message /// The Exception protected void Log(int level, string levelName, object message, Exception exception) { if(logLevel <= level) { System.Diagnostics.Debug.WriteLine(string.Format("[{0}] {1}", levelName, message)); if(exception != null) { System.Diagnostics.Debug.WriteLine(exception.StackTrace); } } } /// /// Just returns this logger (TraceLogger is not hierarchical). /// /// Ignored /// This ILogger instance. public ILogger CreateChildLogger(string name ) { return this; } } }