internal static void LogReadWriteRequest(DateTime dateTime, string channel, ReadWriteRequest[] requests,
                                                 MessageDirection messageDirection, string parentID)
        {
            if (!logTypesConfig.LogReadWriteRequest)
            {
                return;
            }

            ComDriverLogEntry logEntry = new ComDriverLogEntry();
            SoapFormatter     sf       = new SoapFormatter();

            using (MemoryStream ms = new MemoryStream())
            {
                try
                {
                    sf.Serialize(ms, requests);
                }
                catch (SerializationException)
                {
                    throw;
                }
                catch (ArgumentNullException)
                {
                    throw;
                }
                catch (SecurityException)
                {
                    throw;
                }

                logEntry.LogType             = LogType.ReadWriteRequest;
                logEntry.DateTime            = dateTime;
                logEntry.LoggerChannel       = channel;
                logEntry.Text                = Utils.UnspecifiedString;
                logEntry.MessageDirection    = messageDirection;
                logEntry.ParentID            = parentID;
                logEntry.RequestGUID         = Utils.UnspecifiedString;
                logEntry.CurrentRetry        = Utils.UnspecifiedString;
                logEntry.Message             = ms.ToArray();
                logEntry.RequestPropertiesId = _getRequestPropertiesId(requests);
            }

            _write(logEntry);
        }
        internal static void LogConnectionState(DateTime dateTime, string channel, string text)
        {
            if (!logTypesConfig.LogConnectionState)
            {
                return;
            }

            ComDriverLogEntry logEntry = new ComDriverLogEntry();

            logEntry.LogType             = LogType.ConnectionState;
            logEntry.DateTime            = dateTime;
            logEntry.LoggerChannel       = channel;
            logEntry.Text                = text;
            logEntry.MessageDirection    = MessageDirection.Unspecified;
            logEntry.ParentID            = Utils.UnspecifiedString;
            logEntry.RequestGUID         = Utils.UnspecifiedString;
            logEntry.CurrentRetry        = Utils.UnspecifiedString;
            logEntry.Message             = DBNull.Value;
            logEntry.RequestPropertiesId = Utils.UnspecifiedString;

            _write(logEntry);
        }
        internal static void LogReceivedMessageChunk(DateTime dateTime, string channel, byte[] tmpBuffer)
        {
            if (!logTypesConfig.LogReceivedMessageChunk)
            {
                return;
            }

            ComDriverLogEntry logEntry = new ComDriverLogEntry();

            logEntry.LogType             = LogType.ReceivedMessageChunk;
            logEntry.DateTime            = dateTime;
            logEntry.LoggerChannel       = channel;
            logEntry.Text                = Utils.UnspecifiedString;
            logEntry.MessageDirection    = MessageDirection.Received;
            logEntry.ParentID            = Utils.UnspecifiedString;
            logEntry.RequestGUID         = Utils.UnspecifiedString;
            logEntry.CurrentRetry        = Utils.UnspecifiedString;
            logEntry.Message             = tmpBuffer;
            logEntry.RequestPropertiesId = Utils.UnspecifiedString;

            _write(logEntry);
        }
        internal static void LogFullMessage(DateTime dateTime, string channel, string requestGUID,
                                            MessageDirection messageDirection, string currentRetry, object message, string parentID,
                                            string messageDescription)
        {
            if (!logTypesConfig.LogFullMessage)
            {
                return;
            }

            ComDriverLogEntry logEntry = new ComDriverLogEntry();

            logEntry.LogType             = LogType.FullMessage;
            logEntry.DateTime            = dateTime;
            logEntry.LoggerChannel       = channel;
            logEntry.Text                = messageDescription;
            logEntry.MessageDirection    = messageDirection;
            logEntry.ParentID            = parentID;
            logEntry.RequestGUID         = requestGUID;
            logEntry.CurrentRetry        = currentRetry;
            logEntry.Message             = message;
            logEntry.RequestPropertiesId = Utils.UnspecifiedString;

            _write(logEntry);
        }
        private static void _write(ComDriverLogEntry logEntry)
        {
            if (!_openOledbConnection())
            {
                return;
            }

            OleDbCommand cmd = oleDbConnection.CreateCommand();

            try
            {
                lock (objectLocket)
                {
                    using (cmd)
                    {
                        string insertCmd =
                            " INSERT INTO " + Utils.HelperComDriverLogger.ComDriverLogsTableName +
                            " (DateTimeC, Type, Channel, ParentID, GuidC, MessageDirection, CurrentRetry, Message, TextC, RequestPropertiesId) " +
                            " VALUES(@DateTime, @Type, @Channel, @ParentID, @GuidC, @MessageDirection, @CurrentRetry, @Message, @TextC, @RequestPropertiesId)";

                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.Connection  = oleDbConnection;
                        cmd.CommandText = insertCmd;

                        OleDbParameter dateTimeParam = cmd.CreateParameter();
                        dateTimeParam.ParameterName = "@DateTimeC";
                        dateTimeParam.Value         = logEntry.DateTime.Ticks;
                        //dateTimeParam.Value = Utils.HelperComDriverLogger.GetAccessDateTime(logEntry.DateTime);

                        OleDbParameter typeParam = cmd.CreateParameter();
                        typeParam.ParameterName = "@Type";
                        typeParam.Value         = logEntry.LogType.ToString();

                        OleDbParameter channelParam = cmd.CreateParameter();
                        channelParam.ParameterName = "@Channel";
                        channelParam.Value         = logEntry.LoggerChannel;

                        OleDbParameter parentIDParams = cmd.CreateParameter();
                        parentIDParams.ParameterName = "@ParentID";
                        parentIDParams.Value         = logEntry.ParentID;

                        OleDbParameter GUIDParam = cmd.CreateParameter();
                        GUIDParam.ParameterName = "@GuidC";
                        GUIDParam.Value         = logEntry.RequestGUID;

                        OleDbParameter messageDirectionParam = cmd.CreateParameter();
                        messageDirectionParam.ParameterName = "@MessageDirection";
                        messageDirectionParam.Value         = logEntry.MessageDirection.ToString();

                        OleDbParameter currentRetryParam = cmd.CreateParameter();
                        currentRetryParam.ParameterName = "@CurrentRetry";
                        currentRetryParam.Value         = logEntry.CurrentRetry;

                        OleDbParameter messageParam = cmd.CreateParameter();
                        messageParam.ParameterName = "@Message";

                        if (logEntry.Message != DBNull.Value)
                        {
                            messageParam.Value = (logEntry.Message.GetType() == typeof(String))
                                ? ASCIIEncoding.ASCII.GetBytes(logEntry.Message as String)
                                : messageParam.Value = logEntry.Message;
                        }
                        else
                        {
                            messageParam.Value = DBNull.Value;
                        }

                        OleDbParameter textCParam = cmd.CreateParameter();
                        textCParam.ParameterName = "@TextC";
                        textCParam.Value         = logEntry.Text;

                        OleDbParameter requestPropertiesIdParam = cmd.CreateParameter();
                        requestPropertiesIdParam.ParameterName = "@RequestPropertiesId";
                        requestPropertiesIdParam.Value         = logEntry.RequestPropertiesId;

                        cmd.Parameters.AddRange(new OleDbParameter[]
                        {
                            dateTimeParam, typeParam, channelParam, parentIDParams, GUIDParam,
                            messageDirectionParam, currentRetryParam, messageParam, textCParam,
                            requestPropertiesIdParam
                        });

                        if (_openOledbConnection())
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }

                    uint numOfRows = _getDbRowsNo();
                    if (numOfRows >= 100000)
                    {
                        _closeOledbConnection();
                        logFileIndex++;

                        string path = String.Empty;
                        path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName()
                                                     .CodeBase.Replace(@"file:///", ""));
                        string dirSeparator = Path.DirectorySeparatorChar.ToString();
                        if (path.Substring(path.Length - 1) == dirSeparator)
                        {
                            path = path.Substring(0, path.Length - 1);
                        }

                        XAttribute[] xAttributes = new XAttribute[1];
                        xAttributes[0] = new XAttribute("LogFileIndex", logFileIndex);
                        XElement root = new XElement("LogFile", xAttributes);
                        root.Save(path + "\\ComDriverLogs.xml");

                        _openOledbConnection();
                    }
                }
            }
            catch (InvalidOperationException)
            {
                throw;
            }
        }