private void Run() { while (!isTerminal) { if (this.msgQueue.IsEmpty) { Thread.Sleep(5); } else { HostarLogBean bean = null; this.msgQueue.TryDequeue(out bean); if (bean != null) { string log = bean.Message; if (bean.Module == 0) { log = "[前模组]-" + bean.Message; } else if (bean.Module == 1) { log = "[后模组]-" + bean.Message; } switch (bean.LogLevel) { case MsgLevel.Debug: basicLog?.Debug(log); break; case MsgLevel.Info: basicLog?.Info(log); InfoRaised?.Invoke(bean); break; case MsgLevel.Warn: basicLog?.Warn(log); ErrorRaised?.Invoke(bean); break; case MsgLevel.Error: errLog?.Error(log); ErrorRaised?.Invoke(bean); break; case MsgLevel.Fatal: errLog?.Fatal(log); ErrorRaised?.Invoke(bean); break; default: break; } } } } }
public void AddMessage(MsgLevel level, StringCode code, int module = -1, params object[] param) { string str = this.GetResource(code, Language); if (param != null) { str = string.Format(str, param); } HostarLogBean bean = new HostarLogBean(level, str, module); if (bean.LogLevel >= MsgLevel.Warn) { lock (this.ErrLock) { this.msgQueue.Enqueue(bean); } } else { this.msgQueue.Enqueue(bean); } }
public void AddMessage(MsgLevel level, string debug, int module = -1) { HostarLogBean bean = new HostarLogBean(level, debug, module); this.msgQueue.Enqueue(bean); }