Пример #1
0
        /// <summary>
        /// LOG를 기록하기 위한 함수
        /// </summary>
        /// <param name="_LOGTYPE">LOGTYPE[ENUM]</param>
        /// <param name="_DATA">LOG VALUE</param>
        /// <param name="_ONLY_UI">Log Display 처리 유무</param>
        /// <param name="_FILE_WRITE">File Write 유무</param>
        static public void SetLOG(LOGTYPE _LOGTYPE, string _DATA, bool _ONLY_UI = true, bool _FILE_WRITE = true)
        {
            clsLOGMsg clsLOGMsg = new clsLOGMsg
            {
                LogType   = _LOGTYPE.ToString(),
                EventTime = "[" + String.Format("{0:HH:mm:ss.fff}" + "]\t", DateTime.Now).Trim(),
                LOGDATA   = _DATA.Trim()
            };

            try
            {
                if (_FILE_WRITE)
                {
                    //File Write Queue 에 적재
                    lock (Queue_LOG.SyncRoot)
                    {
                        Queue_LOG.Enqueue(clsLOGMsg);    //LOG File Save 용
                    }
                }

                if (_ONLY_UI)
                {
                    if (OnLOG_VIEW != null)
                    {
                        OnLOG_VIEW(_LOGTYPE, _DATA);
                    }
                }

                clsLOGMsg = null;
            }
            catch
            {
            }
        }
Пример #2
0
        /// <summary>
        /// 실제로 LOG를 File Write 를 처리하는 Thread 함수
        /// </summary>
        static private void threadLOGFileWrite()
        {
            string _DirPath       = string.Empty;
            string _FilePath      = string.Empty;
            string Trace_FilePath = string.Empty;

            clsLOGMsg clsMSG = null;

            while (bLOG_Thread == true)
            {
                try
                {
                    clsMSG = null;

                    lock (Queue_LOG.SyncRoot)
                    {
                        if (Queue_LOG.Count > 0)
                        {
                            clsMSG = (clsLOGMsg)Queue_LOG.Dequeue();
                        }
                    }


                    if (clsMSG != null)
                    {
                        _FilePath = String.Format("{0:HH}", DateTime.Now) + ".log";
                        MakeFolder();//경로 유무 확인

                        _FilePath = clsMSG.LogType + "_" + _FilePath;
                        _DirPath  = PATH.LOG_TYPE_PATH.Where(C => C.Key == clsMSG.LogType).FirstOrDefault().Value;

                        if (_DirPath != null)
                        {
                            //해당 경로에 파일 존재 유무 확인
                            if (File.Exists(_DirPath + _FilePath) == true)
                            {
                                using (StreamWriter sw = new StreamWriter(_DirPath + _FilePath, true))
                                {
                                    sw.WriteLine(clsMSG.EventTime + "\t" + clsMSG.LOGDATA);
                                    sw.Close();
                                }
                            }
                            else
                            {
                                using (StreamWriter sw = File.CreateText(_DirPath + _FilePath))
                                {
                                    sw.WriteLine(clsMSG.EventTime + "\t" + clsMSG.LOGDATA);
                                    sw.Close();
                                }
                            }
                        }
                    }

                    //Application.DoEvents();
                    Thread.Sleep(10);
                }
                catch (ThreadAbortException)
                {
                }
                catch { }
            }
        }