📄 level.cs
字号:
#region Copyright & License
//
// Copyright 2001-2005 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.
//
#endregion
using System;
using System.Collections;
namespace log4net.Core
{
/// <summary>
/// Defines the default set of levels recognized by the system.
/// </summary>
/// <remarks>
/// <para>
/// Each <see cref="LoggingEvent"/> has an associated <see cref="Level"/>.
/// </para>
/// <para>
/// Levels have a numeric <see cref="Level.Value"/> that defines the relative
/// ordering between levels. Two Levels with the same <see cref="Level.Value"/>
/// are deemed to be equivalent.
/// </para>
/// <para>
/// The levels that are recognized by log4net are set for each <see cref="log4net.Repository.ILoggerRepository"/>
/// and each repository can have different levels defined. The levels are stored
/// in the <see cref="log4net.Repository.ILoggerRepository.LevelMap"/> on the repository. Levels are
/// looked up by name from the <see cref="log4net.Repository.ILoggerRepository.LevelMap"/>.
/// </para>
/// <para>
/// When logging at level INFO the actual level used is not <see cref="Level.Info"/> but
/// the value of <c>LoggerRepository.LevelMap["INFO"]</c>. The default value for this is
/// <see cref="Level.Info"/>, but this can be changed by reconfiguring the level map.
/// </para>
/// <para>
/// Each level has a <see cref="DisplayName"/> in addition to its <see cref="Name"/>. The
/// <see cref="DisplayName"/> 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.
/// </para>
/// <para>
/// Some of the predefined levels recognized by the system are:
/// </para>
/// <list type="bullet">
/// <item>
/// <description><see cref="Off"/>.</description>
/// </item>
/// <item>
/// <description><see cref="Fatal"/>.</description>
/// </item>
/// <item>
/// <description><see cref="Error"/>.</description>
/// </item>
/// <item>
/// <description><see cref="Warn"/>.</description>
/// </item>
/// <item>
/// <description><see cref="Info"/>.</description>
/// </item>
/// <item>
/// <description><see cref="Debug"/>.</description>
/// </item>
/// <item>
/// <description><see cref="All"/>.</description>
/// </item>
/// </list>
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
#if !NETCF
[Serializable]
#endif
sealed public class Level : IComparable
{
#region Public Instance Constructors
/// <summary>
/// Constructor
/// </summary>
/// <param name="level">Integer value for this level, higher values represent more severe levels.</param>
/// <param name="levelName">The string name of this level.</param>
/// <param name="displayName">The display name for this level. This may be localized or otherwise different from the name</param>
/// <remarks>
/// <para>
/// Initializes a new instance of the <see cref="Level" /> class with
/// the specified level name and value.
/// </para>
/// </remarks>
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;
m_levelName = string.Intern(levelName);
m_levelDisplayName = displayName;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="level">Integer value for this level, higher values represent more severe levels.</param>
/// <param name="levelName">The string name of this level.</param>
/// <remarks>
/// <para>
/// Initializes a new instance of the <see cref="Level" /> class with
/// the specified level name and value.
/// </para>
/// </remarks>
public Level(int level, string levelName) : this(level, levelName, levelName)
{
}
#endregion Public Instance Constructors
#region Public Instance Properties
/// <summary>
/// Gets the name of this level.
/// </summary>
/// <value>
/// The name of this level.
/// </value>
/// <remarks>
/// <para>
/// Gets the name of this level.
/// </para>
/// </remarks>
public string Name
{
get { return m_levelName; }
}
/// <summary>
/// Gets the value of this level.
/// </summary>
/// <value>
/// The value of this level.
/// </value>
/// <remarks>
/// <para>
/// Gets the value of this level.
/// </para>
/// </remarks>
public int Value
{
get { return m_levelValue; }
}
/// <summary>
/// Gets the display name of this level.
/// </summary>
/// <value>
/// The display name of this level.
/// </value>
/// <remarks>
/// <para>
/// Gets the display name of this level.
/// </para>
/// </remarks>
public string DisplayName
{
get { return m_levelDisplayName; }
}
#endregion Public Instance Properties
#region Override implementation of Object
/// <summary>
/// Returns the <see cref="string" /> representation of the current
/// <see cref="Level" />.
/// </summary>
/// <returns>
/// A <see cref="string" /> representation of the current <see cref="Level" />.
/// </returns>
/// <remarks>
/// <para>
/// Returns the level <see cref="Name"/>.
/// </para>
/// </remarks>
override public string ToString()
{
return m_levelName;
}
/// <summary>
/// Compares levels.
/// </summary>
/// <param name="o">The object to compare against.</param>
/// <returns><c>true</c> if the objects are equal.</returns>
/// <remarks>
/// <para>
/// Compares the levels of <see cref="Level" /> instances, and
/// defers to base class if the target object is not a <see cref="Level" />
/// instance.
/// </para>
/// </remarks>
override public bool Equals(object o)
{
Level otherLevel = o as Level;
if (otherLevel != null)
{
return m_levelValue == otherLevel.m_levelValue;
}
else
{
return base.Equals(o);
}
}
/// <summary>
/// Returns a hash code
/// </summary>
/// <returns>A hash code for the current <see cref="Level" />.</returns>
/// <remarks>
/// <para>
/// Returns a hash code suitable for use in hashing algorithms and data
/// structures like a hash table.
/// </para>
/// <para>
/// Returns the hash code of the level <see cref="Value"/>.
/// </para>
/// </remarks>
override public int GetHashCode()
{
return m_levelValue;
}
#endregion Override implementation of Object
#region Implementation of IComparable
/// <summary>
/// Compares this instance to a specified object and returns an
/// indication of their relative values.
/// </summary>
/// <param name="r">A <see cref="Level"/> instance or <see langword="null" /> to compare with this instance.</param>
/// <returns>
/// A 32-bit signed integer that indicates the relative order of the
/// values compared. The return value has these meanings:
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <description>Meaning</description>
/// </listheader>
/// <item>
/// <term>Less than zero</term>
/// <description>This instance is less than <paramref name="r" />.</description>
/// </item>
/// <item>
/// <term>Zero</term>
/// <description>This instance is equal to <paramref name="r" />.</description>
/// </item>
/// <item>
/// <term>Greater than zero</term>
/// <description>
/// <para>This instance is greater than <paramref name="r" />.</para>
/// <para>-or-</para>
/// <para><paramref name="r" /> is <see langword="null" />.</para>
/// </description>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// <paramref name="r" /> must be an instance of <see cref="Level" />
/// or <see langword="null" />; otherwise, an exception is thrown.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"><paramref name="r" /> is not a <see cref="Level" />.</exception>
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -