Exemplo n.º 1
0
        /// <summary>
        /// 日志元素出队列
        /// </summary>
        /// <returns>出队列是否成功</returns>
        public LogElement DeQ()
        {
            lock (lockQ)
            {
                LogElement retElem = null;

                if (errLogQ.Count > 0)
                {
                    retElem = errLogQ.Dequeue();
                }
                else if (infLogQ.Count > 0)
                {
                    retElem = infLogQ.Dequeue();
                }
                else if (CLILogQ.Count > 0)
                {
                    retElem = CLILogQ.Dequeue();
                }
                else
                {
                    retElem = null;
                }

                return(retElem);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 记录信息日志
        /// </summary>
        /// <param name="layer">协议层</param>
        /// <param name="inf">数据</param>
        /// <param name="len">数据量</param>
        public static void RecordInf(enLogLayer layer, byte[] inf, int len = 0)
        {
            lock (lockLog)
            {
                if (layerLogSwitch[(int)layer])
                {
                    LogElement aLogElement = null;

                    if (inf != null && inf.Length != 0)
                    {
                        if (len > inf.Length)
                        {
                            aLogElement = new LogElement(layer, enLogType.eInfo, ToHexString(inf));
                        }
                        else
                        {
                            byte[] arrValid = new byte[len];
                            Array.Copy(inf, 0, arrValid, 0, len);
                            aLogElement = new LogElement(layer, enLogType.eInfo, ToHexString(arrValid));
                        }
                    }

                    logQ.EnQ(aLogElement);
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 记录错误日志
 /// </summary>
 /// <param name="layer">协议层</param>
 /// <param name="err">错误信息</param>
 public static void RecordErr(enLogLayer layer, string err)
 {
     lock (lockLog)
     {
         LogElement aLogElement = new LogElement(layer, enLogType.eErr, err);
         logQ.EnQ(aLogElement);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 记录信息日志
 /// </summary>
 /// <param name="layer">协议层</param>
 /// <param name="inf">信息</param>
 public static void RecordInf(enLogLayer layer, string inf)
 {
     lock (lockLog)
     {
         if (layerLogSwitch[(int)layer])
         {
             LogElement aLogElement = new LogElement(layer, enLogType.eInfo, inf);
             logQ.EnQ(aLogElement);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 日志处理主线程函数
        /// </summary>
        private static void CommStackLogger()
        {
            CommStackLog.RecordInf(enLogLayer.eAdapter, "CommStackLogger running");
            while (!bExit && logQ.HaveLogElement)
            {
                LogElement logElem = logQ.DeQ();
                if (logElem != null)
                {
                    WriteLog(logElem.LogType, logElem.ToString(), logElem.NewLine);
                }
            }

            asigThreadExit.Set();
        }
Exemplo n.º 6
0
 /// <summary>
 /// 日志元素入队列
 /// </summary>
 /// <param name="element">日志元素</param>
 /// <returns>入队列是否成功</returns>
 public bool EnQ(LogElement element)
 {
     lock (lockQ)
     {
         if (element.LogType == enLogType.eErr)
         {
             if (errLogQ.Count >= capacity)
             {
                 return(false);
             }
             else
             {
                 errLogQ.Enqueue(element);
                 sigNewLogElement.Set();
                 return(true);
             }
         }
         else if (element.LogType == enLogType.eInfo)
         {
             if (infLogQ.Count >= capacity)
             {
                 return(false);
             }
             else
             {
                 infLogQ.Enqueue(element);
                 sigNewLogElement.Set();
                 return(true);
             }
         }
         else if (element.LogType == enLogType.eCli)
         {
             if (CLILogQ.Count >= capacity)
             {
                 return(false);
             }
             else
             {
                 CLILogQ.Enqueue(element);
                 sigNewLogElement.Set();
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 记录错误日志
        /// </summary>
        /// <param name="layer">协议层</param>
        /// <param name="err">错误数据</param>
        /// <param name="len">错误数据量</param>
        public static void RecordErr(enLogLayer layer, byte[] err, int len = 0)
        {
            lock (lockLog)
            {
                LogElement aLogElement = null;
                if (err != null && err.Length != 0)
                {
                    if (len > err.Length)
                    {
                        aLogElement = new LogElement(layer, enLogType.eErr, ToHexString(err));
                    }
                    else
                    {
                        byte[] arrValid = new byte[len];
                        Array.Copy(err, 0, arrValid, 0, len);
                        aLogElement = new LogElement(layer, enLogType.eErr, ToHexString(arrValid));
                    }
                }

                logQ.EnQ(aLogElement);
            }
        }