예제 #1
0
 public new virtual void Enqueue(T item)
 {
     base.Enqueue(item);
     if (this.Count >= this.CapLimit)
     {
         LogEngine.DebugWriteLine($"Log capture limit: {this.CapLimit} > Publish!");
         this.Publish();
     }
 }
예제 #2
0
        /// <summary>
        /// The publish.
        /// </summary>
        protected virtual void Publish()
        {
            var task = new Task(
                () =>
            {
                var itemsToLog = new List <T>();
                try
                {
                    if (this.IsPublishing())
                    {
                        return;
                    }

                    this.StartPublishing();
                    //LogEngine.DebugWriteLine($"Log start dequeue {this.Count} items.");
                    T item;
                    while (this.TryDequeue(out item))
                    {
                        itemsToLog.Add(item);
                    }
                }
                catch (ThreadAbortException tex)
                {
                    LogEngine.DebugWriteLine($"Warning-Dequeue items failed > {tex.Message}");

                    LogEngine.WriteLog(
                        Configuration.EngineName,
                        $"Error in {MethodBase.GetCurrentMethod().Name}",
                        Constant.DefconOne,
                        Constant.TaskCategoriesError,
                        tex,
                        EventLogEntryType.Error);
                }
                catch (Exception ex)
                {
                    LogEngine.DebugWriteLine($"Dequeue items failed > {ex.Message}");

                    LogEngine.WriteLog(
                        Configuration.EngineName,
                        $"Error in {MethodBase.GetCurrentMethod().Name}",
                        Constant.DefconOne,
                        Constant.TaskCategoriesError,
                        ex,
                        EventLogEntryType.Error);
                }
                finally
                {
                    //LogEngine.DebugWriteLine($"Log dequeued {itemsToLog.Count} items");
                    this.OnPublish(itemsToLog);
                    this.CompletePublishing();
                }
            });

            task.Start();
        }