//--------------------------------------------------------------
        //Method to send email notifications
        //--------------------------------------------------------------
        public override void SendLogNotifications()
        {
            try
            {
                lockNotif.AcquireWriterLock( WriterLockTimeout );
                XmlDocument xmlPendingNotificationsDoc = new XmlDocument();
                try
                {
                    xmlPendingNotificationsDoc.Load( GetFilePath( PendingNotificationsFile ) );
                }
                catch( FileNotFoundException )
                {
                    //file not found
                    return;
                }

                ArrayList arrLogTypeInfo;
                XMLLoggingProvider x = new XMLLoggingProvider();
                arrLogTypeInfo = x.GetLogTypeConfigInfo();

                PurgeLogBuffer();

                int a;
                for( a = 0; a <= arrLogTypeInfo.Count - 1; a++ )
                {
                    LogTypeConfigInfo objLogTypeInfo;
                    objLogTypeInfo = (LogTypeConfigInfo)arrLogTypeInfo[a];

                    if( objLogTypeInfo.EmailNotificationIsActive )
                    {
                        XmlNodeList xmlPendingNotifications = xmlPendingNotificationsDoc.DocumentElement.SelectNodes( "log[@NotificationLogTypeKey='" + objLogTypeInfo.LogTypeKey + "' and @LogTypePortalID='" + objLogTypeInfo.LogTypePortalID + "' and number(@LogCreateDateNum) > " + DateToNum( objLogTypeInfo.StartDateTime ).ToString() + "]" );

                        if( xmlPendingNotifications.Count >= objLogTypeInfo.NotificationThreshold )
                        {
                            //we have notifications to send out
                            XmlNode xmlPendingNotification;
                            XmlDocument xmlOut = new XmlDocument();
                            xmlOut.LoadXml( "<notification></notification>" );
                            foreach( XmlNode tempLoopVar_xmlPendingNotification in xmlPendingNotifications )
                            {
                                xmlPendingNotification = tempLoopVar_xmlPendingNotification;

                                XmlNode tmpNode;
                                tmpNode = xmlOut.ImportNode( xmlPendingNotification, true );
                                xmlOut.DocumentElement.AppendChild( tmpNode );

                                //Remove the node from the list of pending notifications
                                xmlPendingNotificationsDoc.DocumentElement.RemoveChild( xmlPendingNotification );
                            }

                            bool NotificationFailed = false;
                            string errSendNotif;

                            errSendNotif = Mail.Mail.SendMail( objLogTypeInfo.MailFromAddress, objLogTypeInfo.MailToAddress, "", "Log Notification", xmlOut.OuterXml, "", "", "", "", "", "" );

                            if( !String.IsNullOrEmpty(errSendNotif) )
                            {
                                //notification failed to send
                                NotificationFailed = true;
                            }

                            EventLogController objEventLogController = new EventLogController();
                            if( NotificationFailed )
                            {
                                //Notification failed, log it
                                LogInfo objEventLogInfo = new LogInfo();
                                objEventLogInfo.LogTypeKey = EventLogController.EventLogType.LOG_NOTIFICATION_FAILURE.ToString();
                                objEventLogInfo.AddProperty( "Log Notification Failed: ", errSendNotif );
                                objEventLogController.AddLog( objEventLogInfo );

                                //need to reload the xml doc because
                                //we removed xml nodes above
                                xmlPendingNotificationsDoc.Load( GetFilePath( PendingNotificationsFile ) );

                                if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] == null )
                                {
                                    XmlAttribute xmlNotificationFailed;
                                    xmlNotificationFailed = xmlPendingNotificationsDoc.CreateAttribute( "LastNotificationFailure" );
                                    xmlNotificationFailed.Value = DateTime.Now.ToString();
                                    xmlPendingNotificationsDoc.DocumentElement.Attributes.Append( xmlNotificationFailed );
                                }
                                else
                                {
                                    xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"].Value = DateTime.Now.ToString();
                                }
                                xmlPendingNotificationsDoc.Save( GetFilePath( PendingNotificationsFile ) );
                            }
                            else
                            {
                                //Notification succeeded.
                                //Save the updated pending notifications file
                                //so we remove the notifications that have been completed.
                                if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] != null )
                                {
                                    xmlPendingNotificationsDoc.DocumentElement.Attributes.Remove( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] );
                                }

                                if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationSuccess"] == null )
                                {
                                    XmlAttribute xmlNotificationSucceeded;
                                    xmlNotificationSucceeded = xmlPendingNotificationsDoc.CreateAttribute( "LastNotificationSuccess" );
                                    xmlNotificationSucceeded.Value = DateTime.Now.ToString();
                                    xmlPendingNotificationsDoc.DocumentElement.Attributes.Append( xmlNotificationSucceeded );
                                }
                                else
                                {
                                    xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationSuccess"].Value = DateTime.Now.ToString();
                                }
                                xmlPendingNotificationsDoc.Save( GetFilePath( PendingNotificationsFile ) );
                            }
                        }
                    }
                }

                x.DeleteOldPendingNotifications();
            }
            catch( Exception exc )
            {
                Exceptions.Exceptions.LogException( exc );
            }
            finally
            {
                lockNotif.ReleaseWriterLock();
            }
        }
        public override void PurgeLogBuffer()
        {
            try
            {
                lockPurgeLog.AcquireWriterLock( WriterLockTimeout );
                int i;
                ArrayList c = LogQueue;
                int j = c.Count;
                for( i = 1; i <= c.Count; i++ )
                {
                    //in case the log was removed
                    //by another thread simultaneously
                    if( c[j] != null )
                    {
                        LogQueueItem objLogQueueItem;
                        objLogQueueItem = (LogQueueItem)( c[j] );
                        WriteLog( objLogQueueItem );
                    }
                    //in case the log was removed
                    //by another thread simultaneously
                    if( c[j] != null )
                    {
                        c.Remove( j );
                    }

                    //use "j" instead of "i" so we
                    //can iterate in reverse, taking
                    //items out of the rear of the
                    //collection
                    j--;
                }

                XMLLoggingProvider objMe = new XMLLoggingProvider();
                ArrayList a = objMe.GetLogTypeConfigInfo();
                int k;
                for( k = 0; k <= a.Count - 1; k++ )
                {
                    LogTypeConfigInfo objLogTypeConfigInfo;
                    objLogTypeConfigInfo = (LogTypeConfigInfo)( a[k] );
                    //--------------------------------------------------------------
                    //if the KeepMostRecent setting has a numeric value,
                    //use it to limit the log file to "x" of the most recent
                    //logs, where "x" is the value of KeepMostRecent.
                    //A value of "*" signifies to keep all log entries.
                    //--------------------------------------------------------------
                    if( objLogTypeConfigInfo.KeepMostRecent != "*" && !String.IsNullOrEmpty(objLogTypeConfigInfo.LogFileName) )
                    {
                        XmlDocument xmlLog = new XmlDocument();
                        bool FileExists = false;
                        try
                        {
                            int intAttempts = 0;
                            //wait for up to 100 milliseconds for the file
                            //to be unlocked if it is not available
                            while( !( xmlLog.OuterXml != "" || intAttempts == 100 ) )
                            {
                                intAttempts++;
                                try
                                {
                                    xmlLog.Load( objLogTypeConfigInfo.LogFileNameWithPath );
                                    FileExists = true;
                                }
                                catch( IOException )
                                {
                                    Thread.Sleep( 1 );
                                }
                            }
                        }
                        catch( FileNotFoundException )
                        {
                            FileExists = false;
                            //file doesn't exist
                        }
                        catch( XmlException )
                        {
                            FileExists = false;
                            //file is corrupt
                        }
                        if( FileExists )
                        {
                            XmlNodeList objTotalNodes;
                            if( objLogTypeConfigInfo.LogTypePortalID == "*" )
                            {
                                objTotalNodes = xmlLog.DocumentElement.SelectNodes( "log[@LogTypeKey='" + objLogTypeConfigInfo.LogTypeKey + "']" );
                            }
                            else
                            {
                                objTotalNodes = xmlLog.DocumentElement.SelectNodes( "log[@LogTypeKey='" + objLogTypeConfigInfo.LogTypeKey + "' and LogPortalID='" + objLogTypeConfigInfo.LogTypePortalID + "']" );
                            }

                            int intNodeCount = objTotalNodes.Count;
                            int intKeepMostRecent = Convert.ToInt32( objLogTypeConfigInfo.KeepMostRecent );
                            if( intNodeCount > intKeepMostRecent )
                            {
                                XmlNode objTotalNode;
                                int m = 0;

                                foreach( XmlNode tempLoopVar_objTotalNode in objTotalNodes )
                                {
                                    objTotalNode = tempLoopVar_objTotalNode;
                                    if( intNodeCount - m > intKeepMostRecent )
                                    {
                                        xmlLog.DocumentElement.RemoveChild( objTotalNode );
                                    }
                                    m++;
                                }
                                xmlLog.Save( objLogTypeConfigInfo.LogFileNameWithPath );
                            }
                            else
                            {
                                xmlLog = null;
                            }
                        }
                    }
                }
            }
            finally
            {
                lockPurgeLog.ReleaseWriterLock();
            }
        }