Table of Contents

Class Level

Namespace
log4net.Core
Assembly
log4net.dll

Defines the default set of levels recognized by the system.

public sealed class Level : IComparable
Inheritance
Level
Implements
Inherited Members

Remarks

Each LoggingEvent has an associated Level.

Levels have a numeric Value that defines the relative ordering between levels. Two Levels with the same Value are deemed to be equivalent.

The levels that are recognized by log4net are set for each ILoggerRepository and each repository can have different levels defined. The levels are stored in the LevelMap on the repository. Levels are looked up by name from the LevelMap.

When logging at level INFO the actual level used is not Info but the value of LoggerRepository.LevelMap["INFO"]. The default value for this is Info, but this can be changed by reconfiguring the level map.

Each level has a DisplayName in addition to its Name. The 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.

Some of the predefined levels recognized by the system are:

Constructors

Level(int, string)

Constructor

public Level(int level, string levelName)

Parameters

level int

Integer value for this level, higher values represent more severe levels.

levelName string

The string name of this level.

Remarks

Initializes a new instance of the Level class with the specified level name and value.

Level(int, string, string)

Constructor

public Level(int level, string levelName, string displayName)

Parameters

level int

Integer value for this level, higher values represent more severe levels.

levelName string

The string name of this level.

displayName string

The display name for this level. This may be localized or otherwise different from the name

Remarks

Initializes a new instance of the Level class with the specified level name and value.

Fields

Alert

The Alert level designates very severe error events. Take immediate action, alerts.

public static readonly Level Alert

Field Value

Level

All

The All level designates the lowest level possible.

public static readonly Level All

Field Value

Level

Critical

The Critical level designates very severe error events. Critical condition, critical.

public static readonly Level Critical

Field Value

Level

Debug

The Debug level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Debug

Field Value

Level

Emergency

The Emergency level designates very severe error events. System unusable, emergencies.

public static readonly Level Emergency

Field Value

Level

Error

The Error level designates error events that might still allow the application to continue running.

public static readonly Level Error

Field Value

Level

Fatal

The Fatal level designates very severe error events that will presumably lead the application to abort.

public static readonly Level Fatal

Field Value

Level

Fine

The Fine level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Fine

Field Value

Level

Finer

The Finer level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Finer

Field Value

Level

Finest

The Finest level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Finest

Field Value

Level

Info

The Info level designates informational messages that highlight the progress of the application at coarse-grained level.

public static readonly Level Info

Field Value

Level

Log4Net_Debug

The Emergency level designates very severe error events. System unusable, emergencies.

public static readonly Level Log4Net_Debug

Field Value

Level

Notice

The Notice level designates informational messages that highlight the progress of the application at the highest level.

public static readonly Level Notice

Field Value

Level

Off

The Off level designates a higher level than all the rest.

public static readonly Level Off

Field Value

Level

Severe

The Severe level designates very severe error events.

public static readonly Level Severe

Field Value

Level

Trace

The Trace level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Trace

Field Value

Level

Verbose

The Verbose level designates fine-grained informational events that are most useful to debug an application.

public static readonly Level Verbose

Field Value

Level

Warn

The Warn level designates potentially harmful situations.

public static readonly Level Warn

Field Value

Level

Properties

DisplayName

Gets the display name of this level.

public string DisplayName { get; }

Property Value

string

The display name of this level.

Remarks

Gets the display name of this level.

Name

Gets the name of this level.

public string Name { get; }

Property Value

string

The name of this level.

Remarks

Gets the name of this level.

Value

Gets the value of this level.

public int Value { get; }

Property Value

int

The value of this level.

Remarks

Gets the value of this level.

Methods

Compare(Level, Level)

Compares two specified Level instances.

public static int Compare(Level l, Level r)

Parameters

l Level

The first Level to compare.

r Level

The second Level to compare.

Returns

int

A 32-bit signed integer that indicates the relative order of the two values compared. The return value has these meanings:

ValueMeaning
Less than zerol is less than r.
Zerol is equal to r.
Greater than zerol is greater than r.

Remarks

Compares two levels.

CompareTo(object)

Compares this instance to a specified object and returns an indication of their relative values.

public int CompareTo(object r)

Parameters

r object

A Level instance or null to compare with this instance.

Returns

int

A 32-bit signed integer that indicates the relative order of the values compared. The return value has these meanings:

ValueMeaning
Less than zeroThis instance is less than r.
ZeroThis instance is equal to r.
Greater than zero

This instance is greater than r.

-or-

r is null.

Remarks

r must be an instance of Level or null; otherwise, an exception is thrown.

Exceptions

ArgumentException

r is not a Level.

Equals(object)

Compares levels.

public override bool Equals(object o)

Parameters

o object

The object to compare against.

Returns

bool

true if the objects are equal.

Remarks

Compares the levels of Level instances, and defers to base class if the target object is not a Level instance.

GetHashCode()

Returns a hash code

public override int GetHashCode()

Returns

int

A hash code for the current Level.

Remarks

Returns a hash code suitable for use in hashing algorithms and data structures like a hash table.

Returns the hash code of the level Value.

ToString()

Returns the string representation of the current Level.

public override string ToString()

Returns

string

A string representation of the current Level.

Remarks

Returns the level Name.

Operators

operator ==(Level, Level)

Returns a value indicating whether two specified Level objects have the same value.

public static bool operator ==(Level l, Level r)

Parameters

l Level

A Level or null.

r Level

A Level or null.

Returns

bool

true if the value of l is the same as the value of r; otherwise, false.

Remarks

Compares two levels.

operator >(Level, Level)

Returns a value indicating whether a specified Level is greater than another specified Level.

public static bool operator >(Level l, Level r)

Parameters

l Level

A Level

r Level

A Level

Returns

bool

true if l is greater than r; otherwise, false.

Remarks

Compares two levels.

operator >=(Level, Level)

Returns a value indicating whether a specified Level is greater than or equal to another specified Level.

public static bool operator >=(Level l, Level r)

Parameters

l Level

A Level

r Level

A Level

Returns

bool

true if l is greater than or equal to r; otherwise, false.

Remarks

Compares two levels.

operator !=(Level, Level)

Returns a value indicating whether two specified Level objects have different values.

public static bool operator !=(Level l, Level r)

Parameters

l Level

A Level or null.

r Level

A Level or null.

Returns

bool

true if the value of l is different from the value of r; otherwise, false.

Remarks

Compares two levels.

operator <(Level, Level)

Returns a value indicating whether a specified Level is less than another specified Level.

public static bool operator <(Level l, Level r)

Parameters

l Level

A Level

r Level

A Level

Returns

bool

true if l is less than r; otherwise, false.

Remarks

Compares two levels.

operator <=(Level, Level)

Returns a value indicating whether a specified Level is less than or equal to another specified Level.

public static bool operator <=(Level l, Level r)

Parameters

l Level

A Level

r Level

A Level

Returns

bool

true if l is less than or equal to r; otherwise, false.

Remarks

Compares two levels.