示例#1
0
        protected virtual void WriteAsyn(MvaLoggerEventArgs ea)
        {
            this.queue.Enqueue(ea);
            if (!Monitor.TryEnter(this, 1000))
            {
                return;
            }
            try
            {
                //若還沒結束執行, 先return
                if (this.task != null && !this.task.IsEnd())
                {
                    return;
                }
                this.CloseTask();

                this.task = MvaTask.RunLoop(() =>
                {
                    MvaLoggerEventArgs myea;
                    lock (this)
                    {
                        if (!this.queue.TryDequeue(out myea))
                        {
                            return(true);                                 //取不出來就下次再取
                        }
                    }
                    this.WriteSyn(myea);

                    //若Count等於零, 這個task會結束, IsEnd() = true
                    return(this.queue.Count > 0);
                });
            }
            finally { Monitor.Exit(this); }
        }
示例#2
0
 static void OnEveryLogWrite(object sender, MvaLoggerEventArgs ea)
 {
     if (EhEveryLogWrite == null)
     {
         return;
     }
     EhEveryLogWrite(sender, ea);
 }
示例#3
0
 void OnLogWrite(MvaLoggerEventArgs ea)
 {
     if (this.EhLogWrite == null)
     {
         return;
     }
     this.EhLogWrite(this, ea);
 }
示例#4
0
 protected virtual void WriteSyn(MvaLoggerEventArgs ea)
 {
     this.OnLogWrite(ea);
     OnEveryLogWrite(this, ea);
 }
示例#5
0
 public virtual void Write(MvaLoggerEventArgs ea, MvaLoggerEnumLevel _level)
 {
     ea.Level = _level;
     this.WriteAsyn(ea);
 }
示例#6
0
 /// <summary>
 /// 預設寫Log是用非同步
 /// </summary>
 /// <param name="ea"></param>
 public virtual void Write(MvaLoggerEventArgs ea)
 {
     this.WriteAsyn(ea);
 }