#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you 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.
//
#endregion
using System;
using System.Collections;
namespace log4net.Core
{
///
/// Defines the default set of levels recognized by the system.
///
///
///
/// Each has an associated .
///
///
/// Levels have a numeric that defines the relative
/// ordering between levels. Two Levels with the same
/// are deemed to be equivalent.
///
///
/// The levels that are recognized by log4net are set for each
/// and each repository can have different levels defined. The levels are stored
/// in the on the repository. Levels are
/// looked up by name from the .
///
///
/// When logging at level INFO the actual level used is not but
/// the value of LoggerRepository.LevelMap["INFO"]. The default value for this is
/// , but this can be changed by reconfiguring the level map.
///
///
/// Each level has a in addition to its . The
/// is the string that is written into the output log. By default
/// the display name is the same as the level name, but this can be used to alias levels
/// or to localize the log output.
///
///
/// Some of the predefined levels recognized by the system are:
///
///
/// -
/// .
///
/// -
/// .
///
/// -
/// .
///
/// -
/// .
///
/// -
/// .
///
/// -
/// .
///
/// -
/// .
///
///
///
/// Nicko Cadell
/// Gert Driesen
#if !NETCF
[Serializable]
#endif
public sealed class Level : IComparable
{
#region Public Instance Constructors
///
/// Constructor
///
/// Integer value for this level, higher values represent more severe levels.
/// The string name of this level.
/// The display name for this level. This may be localized or otherwise different from the name
///
///
/// Initializes a new instance of the class with
/// the specified level name and value.
///
///
public Level(int level, string levelName, string displayName)
{
if (levelName == null)
{
throw new ArgumentNullException("levelName");
}
if (displayName == null)
{
throw new ArgumentNullException("displayName");
}
m_levelValue = level;
#if NETSTANDARD1_3
m_levelName = levelName;
#else
m_levelName = string.Intern(levelName);
#endif
m_levelDisplayName = displayName;
}
///
/// Constructor
///
/// Integer value for this level, higher values represent more severe levels.
/// The string name of this level.
///
///
/// Initializes a new instance of the class with
/// the specified level name and value.
///
///
public Level(int level, string levelName) : this(level, levelName, levelName)
{
}
#endregion Public Instance Constructors
#region Public Instance Properties
///
/// Gets the name of this level.
///
///
/// The name of this level.
///
///
///
/// Gets the name of this level.
///
///
public string Name
{
get { return m_levelName; }
}
///
/// Gets the value of this level.
///
///
/// The value of this level.
///
///
///
/// Gets the value of this level.
///
///
public int Value
{
get { return m_levelValue; }
}
///
/// Gets the display name of this level.
///
///
/// The display name of this level.
///
///
///
/// Gets the display name of this level.
///
///
public string DisplayName
{
get { return m_levelDisplayName; }
}
#endregion Public Instance Properties
#region Override implementation of Object
///
/// Returns the representation of the current
/// .
///
///
/// A representation of the current .
///
///
///
/// Returns the level .
///
///
public override string ToString()
{
return m_levelName;
}
///
/// Compares levels.
///
/// The object to compare against.
/// true if the objects are equal.
///
///
/// Compares the levels of instances, and
/// defers to base class if the target object is not a
/// instance.
///
///
public override bool Equals(object o)
{
Level otherLevel = o as Level;
if (otherLevel != null)
{
return m_levelValue == otherLevel.m_levelValue;
}
else
{
return base.Equals(o);
}
}
///
/// Returns a hash code
///
/// A hash code for the current .
///
///
/// Returns a hash code suitable for use in hashing algorithms and data
/// structures like a hash table.
///
///
/// Returns the hash code of the level .
///
///
public override int GetHashCode()
{
return m_levelValue;
}
#endregion Override implementation of Object
#region Implementation of IComparable
///
/// Compares this instance to a specified object and returns an
/// indication of their relative values.
///
/// A instance or to compare with this instance.
///
/// A 32-bit signed integer that indicates the relative order of the
/// values compared. The return value has these meanings:
///
///
/// Value
/// Meaning
///
/// -
/// Less than zero
/// This instance is less than .
///
/// -
/// Zero
/// This instance is equal to .
///
/// -
/// Greater than zero
///
/// This instance is greater than .
/// -or-
/// is .
///
///
///
///
///
///
/// must be an instance of
/// or ; otherwise, an exception is thrown.
///
///
/// is not a .
public int CompareTo(object r)
{
Level target = r as Level;
if (target != null)
{
return Compare(this, target);
}
throw new ArgumentException("Parameter: r, Value: [" + r + "] is not an instance of Level");
}
#endregion Implementation of IComparable
#region Operators
///
/// Returns a value indicating whether a specified
/// is greater than another specified .
///
/// A
/// A
///
/// true if is greater than
/// ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator > (Level l, Level r)
{
return l.m_levelValue > r.m_levelValue;
}
///
/// Returns a value indicating whether a specified
/// is less than another specified .
///
/// A
/// A
///
/// true if is less than
/// ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator < (Level l, Level r)
{
return l.m_levelValue < r.m_levelValue;
}
///
/// Returns a value indicating whether a specified
/// is greater than or equal to another specified .
///
/// A
/// A
///
/// true if is greater than or equal to
/// ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator >= (Level l, Level r)
{
return l.m_levelValue >= r.m_levelValue;
}
///
/// Returns a value indicating whether a specified
/// is less than or equal to another specified .
///
/// A
/// A
///
/// true if is less than or equal to
/// ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator <= (Level l, Level r)
{
return l.m_levelValue <= r.m_levelValue;
}
///
/// Returns a value indicating whether two specified
/// objects have the same value.
///
/// A or .
/// A or .
///
/// true if the value of is the same as the
/// value of ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator == (Level l, Level r)
{
if (((object)l) != null && ((object)r) != null)
{
return l.m_levelValue == r.m_levelValue;
}
else
{
return ((object) l) == ((object) r);
}
}
///
/// Returns a value indicating whether two specified
/// objects have different values.
///
/// A or .
/// A or .
///
/// true if the value of is different from
/// the value of ; otherwise, false.
///
///
///
/// Compares two levels.
///
///
public static bool operator != (Level l, Level r)
{
return !(l==r);
}
#endregion Operators
#region Public Static Methods
///
/// Compares two specified instances.
///
/// The first to compare.
/// The second to compare.
///
/// A 32-bit signed integer that indicates the relative order of the
/// two values compared. The return value has these meanings:
///
///
/// Value
/// Meaning
///
/// -
/// Less than zero
/// is less than .
///
/// -
/// Zero
/// is equal to .
///
/// -
/// Greater than zero
/// is greater than .
///
///
///
///
///
/// Compares two levels.
///
///
public static int Compare(Level l, Level r)
{
// Reference equals
if ((object)l == (object)r)
{
return 0;
}
if (l == null && r == null)
{
return 0;
}
if (l == null)
{
return -1;
}
if (r == null)
{
return 1;
}
return l.m_levelValue.CompareTo(r.m_levelValue);
}
#endregion Public Static Methods
#region Public Static Fields
///
/// The level designates a higher level than all the rest.
///
public static readonly Level Off = new Level(int.MaxValue, "OFF");
///
/// The level designates very severe error events.
/// System unusable, emergencies.
///
public static readonly Level Log4Net_Debug = new Level(120000, "log4net:DEBUG");
///
/// The level designates very severe error events.
/// System unusable, emergencies.
///
public static readonly Level Emergency = new Level(120000, "EMERGENCY");
///
/// The level designates very severe error events
/// that will presumably lead the application to abort.
///
public static readonly Level Fatal = new Level(110000, "FATAL");
///
/// The level designates very severe error events.
/// Take immediate action, alerts.
///
public static readonly Level Alert = new Level(100000, "ALERT");
///
/// The level designates very severe error events.
/// Critical condition, critical.
///
public static readonly Level Critical = new Level(90000, "CRITICAL");
///
/// The level designates very severe error events.
///
public static readonly Level Severe = new Level(80000, "SEVERE");
///
/// The level designates error events that might
/// still allow the application to continue running.
///
public static readonly Level Error = new Level(70000, "ERROR");
///
/// The level designates potentially harmful
/// situations.
///
public static readonly Level Warn = new Level(60000, "WARN");
///
/// The level designates informational messages
/// that highlight the progress of the application at the highest level.
///
public static readonly Level Notice = new Level(50000, "NOTICE");
///
/// The level designates informational messages that
/// highlight the progress of the application at coarse-grained level.
///
public static readonly Level Info = new Level(40000, "INFO");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Debug = new Level(30000, "DEBUG");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Fine = new Level(30000, "FINE");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Trace = new Level(20000, "TRACE");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Finer = new Level(20000, "FINER");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Verbose = new Level(10000, "VERBOSE");
///
/// The level designates fine-grained informational
/// events that are most useful to debug an application.
///
public static readonly Level Finest = new Level(10000, "FINEST");
///
/// The level designates the lowest level possible.
///
public static readonly Level All = new Level(int.MinValue, "ALL");
#endregion Public Static Fields
#region Private Instance Fields
private readonly int m_levelValue;
private readonly string m_levelName;
private readonly string m_levelDisplayName;
#endregion Private Instance Fields
}
}