Table of Contents

Class OnlyOnceErrorHandler

Namespace
log4net.Util
Assembly
log4net.dll

Implements log4net's default error handling policy which consists of emitting a message for the first error in an appender and ignoring all subsequent errors.

public class OnlyOnceErrorHandler : IErrorHandler
Inheritance
OnlyOnceErrorHandler
Implements
Inherited Members

Remarks

The error message is processed using the LogLog sub-system by default.

This policy aims at protecting an otherwise working application from being flooded with error messages when logging fails.

Constructors

OnlyOnceErrorHandler()

Default Constructor

public OnlyOnceErrorHandler()

Remarks

Initializes a new instance of the OnlyOnceErrorHandler class.

OnlyOnceErrorHandler(string)

Constructor

public OnlyOnceErrorHandler(string prefix)

Parameters

prefix string

The prefix to use for each message.

Remarks

Initializes a new instance of the OnlyOnceErrorHandler class with the specified prefix.

Properties

EnabledDate

The date the first error that trigged this error handler occured.

public DateTime EnabledDate { get; }

Property Value

DateTime

ErrorCode

The error code from the first error that trigged this error handler.

public ErrorCode ErrorCode { get; }

Property Value

ErrorCode

Remarks

Defaults to GenericFailure

ErrorMessage

The message from the first error that trigged this error handler.

public string ErrorMessage { get; }

Property Value

string

Exception

The exception from the first error that trigged this error handler.

public Exception Exception { get; }

Property Value

Exception

Remarks

May be null.

IsEnabled

Is error logging enabled

public bool IsEnabled { get; }

Property Value

bool

Remarks

Is error logging enabled. Logging is only enabled for the first error delivered to the OnlyOnceErrorHandler.

Methods

Error(string)

Log an error

public void Error(string message)

Parameters

message string

The error message.

Remarks

Invokes FirstError(string, Exception, ErrorCode) if and only if this is the first error or the first error after Reset() has been called.

Error(string, Exception)

Log an Error

public void Error(string message, Exception e)

Parameters

message string

The error message.

e Exception

The exception.

Remarks

Invokes FirstError(string, Exception, ErrorCode) if and only if this is the first error or the first error after Reset() has been called.

Error(string, Exception, ErrorCode)

Log an Error

public void Error(string message, Exception e, ErrorCode errorCode)

Parameters

message string

The error message.

e Exception

The exception.

errorCode ErrorCode

The internal error code.

Remarks

Invokes FirstError(string, Exception, ErrorCode) if and only if this is the first error or the first error after Reset() has been called.

FirstError(string, Exception, ErrorCode)

Log the very first error

public virtual void FirstError(string message, Exception e, ErrorCode errorCode)

Parameters

message string

The error message.

e Exception

The exception.

errorCode ErrorCode

The internal error code.

Remarks

Sends the error information to LogLog's Error method.

Reset()

Reset the error handler back to its initial disabled state.

public void Reset()