private void SyncFileWriter()
        {
            while (true)
            {
                TextTraceMsg item = null;

                if (_isDisposed)
                {
                    break;
                }

                try
                {
                    object queueObject = null;
                    if (_messageQ.Count > 0)
                    {
                        queueObject = _messageQ.Dequeue();
                    }
                    else
                    {
                        _newMsgArrived.WaitOne();
                        continue;
                    }

                    item = (TextTraceMsg)queueObject;
                    if (item.IsFlushMsg)
                    {
                        if (base.Writer != null)
                        {
                            base.Writer.Close();
                            base.Writer = null;
                        }
                        break;
                    }

                    switch (item.Operation)
                    {
                    case FileOperation.WriteLine:
                        if (base.Writer == null)
                        {
                            base.Writer = new StreamWriter(new ChoFileStreamWithBackup(FilePath,
                                                                                       _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        }
                        base.Writer.WriteLine(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.Write:
                        if (base.Writer == null)
                        {
                            base.Writer = new StreamWriter(new ChoFileStreamWithBackup(FilePath,
                                                                                       _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        }
                        base.Writer.Write(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.CreateNew:
                        base.Writer = new StreamWriter(new ChoFileStreamWithBackup(item.LogFilePath,
                                                                                   _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        break;

                    case FileOperation.Rename:
                        base.Writer = new StreamWriter(new ChoFileStreamWithBackup(item.LogFilePath, _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        if (File.Exists(item.PrevLogFilePath))
                        {
                            using (StreamReader reader = File.OpenText(item.PrevLogFilePath))
                                base.Writer.WriteLine(reader.ReadToEnd());
                        }
                        break;
                    }
                }
                catch (IOException ioEx)
                {
                    string errMsg;
                    if (item != null)
                    {
                        errMsg = String.Format("Error while writing the below message.{0}{1}{0}Exception: {2}", Environment.NewLine,
                                               item.ToString(), ioEx.ToString());
                    }
                    else
                    {
                        errMsg = ioEx.ToString();
                    }

#if !NETSTANDARD2_0
                    ChoETLFramework.WriteToEventLog(errMsg, EventLogEntryType.Error);
#endif
                    //Environment.Exit(-100);
                }
                catch (Exception ex)
                {
                    string errMsg;
                    if (item != null)
                    {
                        errMsg = String.Format("Error while writing the below message.{0}{1}{0}Exception: {2}", Environment.NewLine,
                                               item.ToString(), ex.ToString());
                    }
                    else
                    {
                        errMsg = ex.ToString();
                    }

#if !NETSTANDARD2_0
                    ChoETLFramework.WriteToEventLog(errMsg, EventLogEntryType.Error);
#endif
                }
            }
        }
        private void SyncFileWriter()
        {
            while (true)
            {
                TextTraceMsg item = null;

                try
                {
                    object queueObject = null;
                    if (_messageQ.Count > 0)
                    {
                        queueObject = _messageQ.Dequeue();
                    }
                    else
                    {
                        _newMsgArrived.WaitOne();
                        continue;
                    }

                    item = (TextTraceMsg)queueObject;
                    if (item.IsFlushMsg)
                    {
                        break;
                    }

                    switch (item.Operation)
                    {
                    case FileOperation.WriteLine:
                        if (base.Writer == null)
                        {
                            lock (LogFileManager.SyncRoot)
                            {
                                base.Writer = LogFileManager.GetWriter(item.LogFilePath);
                                if (base.Writer == null)
                                {
                                    base.Writer = LogFileManager.Add(item.LogFilePath, new StreamWriter(new ChoFileStreamWithBackup(FilePath,
                                                                                                                                    _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg)));
                                }
                            }
                        }
                        base.Writer.WriteLine(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.Write:
                        if (base.Writer == null)
                        {
                            lock (LogFileManager.SyncRoot)
                            {
                                base.Writer = LogFileManager.GetWriter(item.LogFilePath);
                                if (base.Writer == null)
                                {
                                    base.Writer = LogFileManager.Add(item.LogFilePath, new StreamWriter(new ChoFileStreamWithBackup(FilePath,
                                                                                                                                    _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg)));
                                }
                            }
                        }
                        base.Writer.Write(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.CreateNew:
                        LogFileManager.Remove(item.LogFilePath);
                        base.Writer = LogFileManager.Add(item.LogFilePath, new StreamWriter(new ChoFileStreamWithBackup(item.LogFilePath,
                                                                                                                        _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg)));
                        break;

                    case FileOperation.Rename:
                        base.Writer = LogFileManager.Add(item.LogFilePath, new StreamWriter(new ChoFileStreamWithBackup(item.LogFilePath, _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg)));
                        if (File.Exists(item.PrevLogFilePath))
                        {
                            using (StreamReader reader = File.OpenText(item.PrevLogFilePath))
                                base.Writer.WriteLine(reader.ReadToEnd());

                            LogFileManager.Remove(item.PrevLogFilePath);
                            //File.Delete(Path.Combine(_directoryName, Path.ChangeExtension(item.PrevLogFilePath, _fileExt)));
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    string errMsg;
                    if (item != null)
                    {
                        errMsg = String.Format("Error while writing the below message.{0}{1}{0}Exception: {2}", Environment.NewLine,
                                               item.ToString(), ex.ToString());
                    }
                    else
                    {
                        errMsg = ex.ToString();
                    }

                    ChoApplication.WriteToEventLog(errMsg, EventLogEntryType.Error);
                }
            }
        }