123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- #region Apache License
- #endregion
- using System;
- using log4net.Core;
- namespace log4net.Util
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class OnlyOnceErrorHandler : IErrorHandler
- {
- #region Public Instance Constructors
-
-
-
-
-
-
-
-
- public OnlyOnceErrorHandler()
- {
- m_prefix = "";
- }
-
-
-
-
-
-
-
-
-
-
- public OnlyOnceErrorHandler(string prefix)
- {
- m_prefix = prefix;
- }
- #endregion Public Instance Constructors
- #region Public Instance Methods
-
-
-
- public void Reset()
- {
- m_enabledDateUtc = DateTime.MinValue;
- m_errorCode = ErrorCode.GenericFailure;
- m_exception = null;
- m_message = null;
- m_firstTime = true;
- }
- #region Implementation of IErrorHandler
-
-
-
-
-
-
-
-
-
-
-
- public void Error(string message, Exception e, ErrorCode errorCode)
- {
- if (m_firstTime)
- {
- FirstError(message, e, errorCode);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- public virtual void FirstError(string message, Exception e, ErrorCode errorCode) {
- m_enabledDateUtc = DateTime.UtcNow;
- m_errorCode = errorCode;
- m_exception = e;
- m_message = message;
- m_firstTime = false;
- if (LogLog.InternalDebugging && !LogLog.QuietMode) {
- LogLog.Error(declaringType, "[" + m_prefix + "] ErrorCode: " + errorCode.ToString() + ". " + message, e);
- }
- }
-
-
-
-
-
-
-
-
-
-
- public void Error(string message, Exception e)
- {
- Error(message, e, ErrorCode.GenericFailure);
- }
-
-
-
-
-
-
-
-
-
- public void Error(string message)
- {
- Error(message, null, ErrorCode.GenericFailure);
- }
- #endregion Implementation of IErrorHandler
- #endregion
- #region Public Instance Properties
-
-
-
-
-
-
-
-
-
- public bool IsEnabled
- {
- get { return m_firstTime; }
- }
-
-
-
- public DateTime EnabledDate
- {
- get
- {
- if (m_enabledDateUtc == DateTime.MinValue) return DateTime.MinValue;
- return m_enabledDateUtc.ToLocalTime();
- }
- }
-
-
-
- public DateTime EnabledDateUtc
- {
- get { return m_enabledDateUtc; }
- }
-
-
-
- public string ErrorMessage
- {
- get { return m_message; }
- }
-
-
-
-
-
-
- public Exception Exception
- {
- get { return m_exception; }
- }
-
-
-
-
-
-
- public ErrorCode ErrorCode
- {
- get { return m_errorCode; }
- }
- #endregion
- #region Private Instance Fields
-
-
-
- private DateTime m_enabledDateUtc;
-
-
-
- private bool m_firstTime = true;
-
-
-
- private string m_message = null;
-
-
-
- private Exception m_exception = null;
-
-
-
- private ErrorCode m_errorCode = ErrorCode.GenericFailure;
-
-
-
- private readonly string m_prefix;
- #endregion Private Instance Fields
- #region Private Static Fields
-
-
-
-
-
-
-
- private readonly static Type declaringType = typeof(OnlyOnceErrorHandler);
- #endregion
- }
- }
|