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); } }
static void OnEveryLogWrite(object sender, MvaLoggerEventArgs ea) { if (EhEveryLogWrite == null) { return; } EhEveryLogWrite(sender, ea); }
void OnLogWrite(MvaLoggerEventArgs ea) { if (this.EhLogWrite == null) { return; } this.EhLogWrite(this, ea); }
protected virtual void WriteSyn(MvaLoggerEventArgs ea) { this.OnLogWrite(ea); OnEveryLogWrite(this, ea); }
public virtual void Write(MvaLoggerEventArgs ea, MvaLoggerEnumLevel _level) { ea.Level = _level; this.WriteAsyn(ea); }
/// <summary> /// 預設寫Log是用非同步 /// </summary> /// <param name="ea"></param> public virtual void Write(MvaLoggerEventArgs ea) { this.WriteAsyn(ea); }