Example #1
0
        public static void AddMessage(int icon, string msg)
        {
            string fullMsg = icon + "|" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "|" + msg;

            if (LogFile != "" && LogEnabled)
            {
                try
                {
                    File.AppendAllText(LogFile, fullMsg + "\r\n");
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error adding process");
                }
            }

            while (_oldMessages.Count > 3000)
            {
                _oldMessages.RemoveAt(0);
            }

            _oldMessages.Add(fullMsg);

            if (MessageConsumer == null)
            {
                return;
            }

            try
            {
                for (int i = 0; i < MessageConsumer.GetInvocationList().Length;)
                {
                    Delegate d = MessageConsumer.GetInvocationList()[i];
                    try
                    {
                        d.DynamicInvoke(new object[] { fullMsg });
                        i++;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error adding message");
                        MessageConsumer -= (StatusStringChange)d;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error adding message");
            }
        }
Example #2
0
        public static void AddMessage(int icon, string msg)
        {
            string fullMsg = icon + "|" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "|" + msg;

            if (Settings.SaveToLog && Settings.LogFile != "")
            {
                try
                {
                    File.AppendAllText(Settings.LogFile, fullMsg + "\r\n");
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error sending message: " + msg);
                }
            }

            while (OldMessages.Count > 3000)
            {
                OldMessages.RemoveAt(0);
            }

            OldMessages.Add(fullMsg);

            if (MessageConsumer != null)
            {
                foreach (Delegate d in MessageConsumer.GetInvocationList())
                {
                    try
                    {
                        d.DynamicInvoke(new object[] { fullMsg });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error sending message: " + fullMsg);
                    }
                }
            }
        }