// edtFTPnet // // Copyright (C) 2004 Enterprise Distributed Technologies Ltd // // www.enterprisedt.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Bug fixes, suggestions and comments should posted on // http://www.enterprisedt.com/forums/index.php // // Change Log: // // $Log: Level.cs,v $ // Revision 1.4 2004/10/29 09:42:30 bruceb // removed /// from file headers // // // namespace EnterpriseDT.Util.Debug { /// /// Simple debug level class. Uses the same interface (but /// not implementation) as log4net, so that the debug /// classes could be easily replaced by log4net /// /// Bruce Blackshaw /// /// $LastChangedRevision$ /// public class Level { internal const int OFF_INT = -1; private const string OFF_STR = "OFF"; internal const int FATAL_INT = 0; private const string FATAL_STR = "FATAL"; internal const int ERROR_INT = 1; private const string ERROR_STR = "ERROR"; internal const int WARN_INT = 2; private const string WARN_STR = "WARN"; internal const int INFO_INT = 3; private const string INFO_STR = "INFO"; internal const int DEBUG_INT = 4; private const string DEBUG_STR = "DEBUG"; internal const int ALL_INT = 10; private const string ALL_STR = "ALL"; internal const int LEVEL_COUNT = 5; /// Off level public static Level OFF = new Level(OFF_INT, OFF_STR); /// Fatal level public static Level FATAL = new Level(FATAL_INT, FATAL_STR); /// OFF level public static Level ERROR = new Level(ERROR_INT, ERROR_STR); /// Warn level public static Level WARN = new Level(WARN_INT, WARN_STR); /// Info level public static Level INFO = new Level(INFO_INT, INFO_STR); /// Debug level public static Level DEBUG = new Level(DEBUG_INT, DEBUG_STR); /// All level public static Level ALL = new Level(ALL_INT, ALL_STR); /// The level's integer value private int level = OFF_INT; /// The level's string representation private string levelStr; /// /// Private constructor so no-one outside the class can /// create any more instances /// /// level to set this instance at /// /// string representation /// private Level(int level, string levelStr) { this.level = level; this.levelStr = levelStr; } /// /// Get integer log level /// /// log level /// internal int GetLevel() { return level; } /// Is this level greater or equal to the supplied level /// /// /// level to test against /// /// true if greater or equal to, false if less than /// internal bool IsGreaterOrEqual(Level l) { if (this.level >= l.level) return true; return false; } /// Get level from supplied string /// /// /// level as a string /// /// level object or null if not found /// internal static Level GetLevel(string level) { if (OFF.ToString().ToUpper().Equals(level.ToUpper())) return OFF; if (FATAL.ToString().ToUpper().Equals(level.ToUpper())) return FATAL; if (ERROR.ToString().ToUpper().Equals(level.ToUpper())) return ERROR; if (WARN.ToString().ToUpper().Equals(level.ToUpper())) return WARN; if (INFO.ToString().ToUpper().Equals(level.ToUpper())) return INFO; if (DEBUG.ToString().ToUpper().Equals(level.ToUpper())) return DEBUG; if (ALL.ToString().ToUpper().Equals(level.ToUpper())) return ALL; return null; } /// String representation /// /// /// string /// public override string ToString() { return levelStr; } } }