Beispiel #1
0
        public void WriteEntry(Exception ex, int errorCode)
        {
            string     message;
            string     logKey       = this.MakeLogKey(ex, errorCode);
            LogCounter counter      = this.GetLogCounter(logKey);
            bool       needRefresh  = false;
            bool       needWriteLog = true;

            lock (this.LogCounterList)
            {
                counter = this.GetLogCounter(logKey);
                if (counter == null)
                {
                    counter = new LogCounter();
                    this.LogCounterList.Add(logKey, counter);
                }
                else
                {
                    needRefresh  = counter.NeedRefresh();
                    needWriteLog = counter.NeedWriteLog();
                    if (needRefresh)
                    {
                        counter.Refresh();
                    }
                    else
                    {
                        counter.Increase();
                    }
                }
            }
            if (needWriteLog)
            {
                message = this.TruncateForEventLog(ex.ToString());
                this.BaseWriteEntry(message, EventLogEntryType.Error, errorCode);
            }
            else if (needRefresh)
            {
                message = string.Format("{0} of {1} skipped.", counter.SkippedCounter, logKey);
                this.BaseWriteEntry(message, EventLogEntryType.Information, 0);
            }
            if (IsTraced)
            {
                Tracer.Instance.Write(TraceClass, "WriteEntry", ex, errorCode);
            }
        }
Beispiel #2
0
 public void WriteEntry(Exception ex, int errorCode)
 {
     string message;
     string logKey = this.MakeLogKey(ex, errorCode);
     LogCounter counter = this.GetLogCounter(logKey);
     bool needRefresh = false;
     bool needWriteLog = true;
     lock (this.LogCounterList)
     {
         counter = this.GetLogCounter(logKey);
         if (counter == null)
         {
             counter = new LogCounter();
             this.LogCounterList.Add(logKey, counter);
         }
         else
         {
             needRefresh = counter.NeedRefresh();
             needWriteLog = counter.NeedWriteLog();
             if (needRefresh)
             {
                 counter.Refresh();
             }
             else
             {
                 counter.Increase();
             }
         }
     }
     if (needWriteLog)
     {
         message = this.TruncateForEventLog(ex.ToString());
         this.BaseWriteEntry(message, EventLogEntryType.Error, errorCode);
     }
     else if (needRefresh)
     {
         message = string.Format("{0} of {1} skipped.", counter.SkippedCounter, logKey);
         this.BaseWriteEntry(message, EventLogEntryType.Information, 0);
     }
     if (IsTraced)
     {
         Tracer.Instance.Write(TraceClass, "WriteEntry", ex, errorCode);
     }
 }