示例#1
0
        private bool WriteMessageToTextRetryQueue(PFLogMessage logMessage)
        {
            PFTextFile logfile           = new PFTextFile(_logFileConnectionString, PFFileOpenOperation.OpenFileForAppend);
            bool       logWriteSucceeded = false;

            try
            {
                logWriteSucceeded = false;
            }
            catch
            {
                logWriteSucceeded = false;
            }
            finally
            {
                if (logfile != null)
                {
                    if (logfile.FileIsOpen)
                    {
                        logfile.CloseFile();
                    }
                }
                logfile = null;
            }

            if (!logWriteSucceeded)
            {
                SaveLogMessageToRetryQueue(logMessage);
            }

            return(logWriteSucceeded);
        }
示例#2
0
        private bool WriteMessageToDatabaseRetryQueue(PFLogMessage logMessage)
        {
            PFDatabase db = new PFDatabase(DatabasePlatform.SQLServerCE35);
            bool       logWriteSucceeded = false;

            try
            {
                logWriteSucceeded = false;
            }
            catch
            {
                logWriteSucceeded = false;
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }

            if (!logWriteSucceeded)
            {
                SaveLogMessageToRetryQueue(logMessage);
            }

            return(logWriteSucceeded);
        }
        /// <summary>
        /// Used by unit test routines to fill up a retry queue with dummy messages.
        /// </summary>
        /// <param name="logMessage">Text of message to be logged.</param>
        /// <returns></returns>
        public bool  WriteMessageToLogRetryQueue(PFLogMessage logMessage)
        {
            bool logWriteSucceeded = false;

            logWriteSucceeded = WriteMessageToTextRetryQueue(logMessage);

            return(logWriteSucceeded);
        }
示例#4
0
        //methods

        /// <summary>
        /// Writes message to message log encapsulated by this instance of PFLogManager.
        /// </summary>
        /// <param name="logMessage">Text of message to be written to log.</param>
        public void WriteMessageToLog(PFLogMessage logMessage)
        {
            if (_logFileStorageType == enLogFileStorageType.Database)
            {
                WriteMessageToDatabaseLog(logMessage, true);
            }
            else if (_logFileStorageType == enLogFileStorageType.TextFile)
            {
                WriteMessageToTextLog(logMessage);
            }
            else
            {
                _msg.Length = 0;
                _msg.Append("Unexpected or invalid storage type for log: ");
                _msg.Append(_logFileStorageType.ToString("0"));
                throw new System.Exception(_msg.ToString());
            }
        }
示例#5
0
        /// <summary>
        /// Used by unit test routines to fill up a retry queue with dummy messages.
        /// </summary>
        /// <param name="logMessage">Text of message to be logged.</param>
        /// <returns>True if log write succeeded.</returns>
        public bool WriteMessageToLogRetryQueue(PFLogMessage logMessage)
        {
            bool logWriteSucceeded = false;

            if (_logFileStorageType == enLogFileStorageType.Database)
            {
                logWriteSucceeded = WriteMessageToDatabaseRetryQueue(logMessage);
            }
            else if (_logFileStorageType == enLogFileStorageType.TextFile)
            {
                logWriteSucceeded = WriteMessageToTextRetryQueue(logMessage);
            }
            else
            {
                _msg.Length = 0;
                _msg.Append("Unexpected or invalid storage type for log: ");
                _msg.Append(_logFileStorageType.ToString("0"));
                throw new System.Exception(_msg.ToString());
            }

            return(logWriteSucceeded);
        }
示例#6
0
        private void SaveLogMessageToRetryQueue(PFLogMessage logMessage)
        {
            _logRetryQueue.Add(logMessage);

            SaveRetryQueue();
        }
示例#7
0
 private bool WriteMessageToTextLog(PFLogMessage logMessage)
 {
     return(WriteMessageToTextLog(logMessage, true));
 }
示例#8
0
        private bool WriteMessageToDatabaseLog(PFLogMessage logMessage, bool saveFailedWriteToRetryQueue)
        {
            PFDatabase db = new PFDatabase(DatabasePlatform.SQLServerCE35);
            bool       logWriteSucceeded = false;
            string     sqlStmt           = string.Empty;
            string     messageText       = string.Empty;
            string     logObject         = string.Empty;

            try
            {
                db.ConnectionString = _logFileConnectionString;
                db.OpenConnection();

                if (logMessage.LogMessageDateTime == DateTime.MinValue)
                {
                    logMessage.LogMessageDateTime = DateTime.Now;
                }
                messageText = logMessage.MessageText.Replace("'", "");
                logObject   = logMessage.ToXmlString().Replace("'", "");

                sqlStmt = _dbLogInsertStatement.Replace("<LogEntryDateTime>", "'" + logMessage.LogMessageDateTime.ToString("MM/dd/yyyy HH:mm:ss") + "'")
                          .Replace("<ApplicationName>", "'" + logMessage.ApplicationName + "'")
                          .Replace("<MachineName>", "'" + logMessage.MachineName + "'")
                          .Replace("<Username>", "'" + logMessage.Username + "'")
                          .Replace("<MessageLevel>", "'" + logMessage.LogMessageType.ToString() + "'")
                          .Replace("<MessageText>", "'" + messageText + "'")
                          .Replace("<LogMessageObject>", "'" + logObject + "'")
                ;

                int numRecsAffected = db.RunNonQuery(sqlStmt, System.Data.CommandType.Text);

                if (numRecsAffected > 0)
                {
                    logWriteSucceeded = true;
                }
                else
                {
                    logWriteSucceeded = false;
                }
            }
            catch
            {
                logWriteSucceeded = false;
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }

            if (!logWriteSucceeded && saveFailedWriteToRetryQueue)
            {
                SaveLogMessageToRetryQueue(logMessage);
            }

            return(logWriteSucceeded);
        }
        //methods

        /// <summary>
        /// Writes message to message log encapsulated by this instance of PFLogManager.
        /// </summary>
        /// <param name="logMessage">Text of message to be written to log.</param>
        public void WriteMessageToLog(PFLogMessage logMessage)
        {
            WriteMessageToTextLog(logMessage);
        }