Class OnlyOnceErrorHandler
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
prefixstringThe 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
ErrorCode
The error code from the first error that trigged this error handler.
public ErrorCode ErrorCode { get; }
Property Value
Remarks
Defaults to GenericFailure
ErrorMessage
The message from the first error that trigged this error handler.
public string ErrorMessage { get; }
Property Value
Exception
The exception from the first error that trigged this error handler.
public Exception Exception { get; }
Property Value
Remarks
May be null.
IsEnabled
Is error logging enabled
public bool IsEnabled { get; }
Property Value
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
messagestringThe 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
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
messagestringThe error message.
eExceptionThe exception.
errorCodeErrorCodeThe 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
messagestringThe error message.
eExceptionThe exception.
errorCodeErrorCodeThe 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()