Example #1
0
 /// <summary>
 /// 将表上下线信息存储到文件
 /// </summary>
 /// <param name="msg"></param>
 public void Write(MeterLogMsg msg)
 {
     lock (_object)
     {
         _meterMsgs.Enqueue(msg);
     }
 }
Example #2
0
        /// <summary>
        /// 将采集服务器监测信息存储到文件
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool WriteMeterLogFile(MeterLogMsg msg)
        {
            LogStreamWriter sm = null;// this._dpLogStreamList.Where(p => p.DtuID == msg.DTUID && p.DataPointID == msg.DataPointID).Single();

            if (this._meterLogStreamList.Count > 0)
            {
                List <LogStreamWriter> list = this._meterLogStreamList.ToList();
                if (list.Count == 1)
                {
                    sm = list[0];
                }
            }
            if (sm == null)
            {
                //记录该监视信息对象不存在,创建该对象。
                sm = CreateMeterLog();
                this._meterLogStreamList.Add(sm);
            }
            if (DateTime.Now >= sm.TimeSign)
            {
                sm.Close();
                this._meterLogStreamList.Remove(sm);
                //创建新日志文件
                sm = CreateMeterLog();
                this._meterLogStreamList.Add(sm);
            }
            //记录日志
            try
            {
                sm.WriteLine(msg.text);
                sm.Flush();
                return(true);
            }
            catch
            {
                sm.Close();
                //如果写流失败
                this._meterLogStreamList.Remove(sm);
                return(false);
            }
        }
Example #3
0
        private void work()
        {
            while (state)
            {
                if (System.AppDomain.CurrentDomain.IsFinalizingForUnload())
                {
                    break;
                }
                ////判断队列中是否存在待写入的日志
                if (_monitorMsgs.Count > 0)
                {
                    MonitorLogMsg msg = _monitorMsgs.Dequeue();
                    WriteHisMonitorInfoLogFile(msg);
                }
                if (_meterMsgs.Count > 0)
                {
                    MeterLogMsg msg = _meterMsgs.Dequeue();
                    WriteMeterLogFile(msg);
                }
                if (msgs.Count > 0)
                {
                    Msg msg = null;
                    lock (msgs)
                    {
                        msg = msgs.Dequeue();
                    }
                    if (msg != null)
                    {
                        FileWrite(msg);
                    }
                }
                if (_dtuMsgs.Count > 0)
                {
                    DTULogMsg _msg = _dtuMsgs.Dequeue();
                    WriteDTULogFile(_msg);
                }

                if (_oneMeterDataLogMsg.Count > 0)
                {
                    OneMeterDataLogMsg _msg = _oneMeterDataLogMsg.Dequeue();
                    WriteOneMeterDataLogFile(_msg);
                }
                if (!(msgs.Count > 0 || _dtuMsgs.Count > 0 || _monitorMsgs.Count > 0 || _meterMsgs.Count > 0 || _oneMeterDataLogMsg.Count > 0))
                {
                    Thread.Sleep(100);
                }
            }
            //关闭所有缓存日志文件
            foreach (LogStreamWriter sm in _dpLogStreamList)
            {
                sm.Close();
            }
            foreach (LogStreamWriter sm in _dtuLogStreamList)
            {
                sm.Close();
            }
            foreach (LogStreamWriter sm in _monitorinfoLogStreamList)
            {
                sm.Close();
            }
            foreach (LogStreamWriter sm in _meterLogStreamList)
            {
                sm.Close();
            }
            foreach (LogStreamWriter sm in _oneMeterDataLogStreamList)
            {
                sm.Close();
            }
            //关闭系统日志
            FileClose();
        }