public void AddLog(LogEntry l)
 {
     m_items.Add (l);
     if (m_items.Count >= Engine.Instance.Storage.GetInt ("gui.log_limit"))
         m_items.RemoveAt (0);
     RefreshUI ();
 }
示例#2
0
        // ----------------------------------------------------
        // Logging
        // ----------------------------------------------------
        public virtual void OnLog(LogEntry l)
        {
            // An exception, to have a clean, standard 'man' output without logging header.
            if (CommandLine.SystemEnvironment.Exists("help"))
            {
                Console.WriteLine(l.Message);
                return;
            }

            if (l.Type != LogType.Realtime)
            {
                string lines = l.GetStringLines().Trim();

                if (Storage != null)
                {
                    lock (Storage)
                    {
                        if (Storage.Get("console.mode") == "batch")
                            Console.WriteLine(lines);
                        if (Storage.Get("console.mode") == "keys")
                            Console.WriteLine(lines);

                        if (Storage.GetBool("log.file.enabled"))
                        {
                            try
                            {
                                string logPath = Storage.Get("log.file.path").Trim();
                                Encoding encoding = Storage.GetEncoding("log.file.encoding");

                                List<string> paths = Logs.ParseLogFilePath(logPath);
                                foreach (string path in paths)
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                                    string text = Platform.Instance.NormalizeString(lines + "\n");
                                    Platform.Instance.FileContentsAppendText(path, text, encoding);
                                }
                            }
                            catch(Exception e)
                            {
                                Logs.Log(LogType.Warning, MessagesFormatter.Format("Log to file disabled due to error, {1}", e.Message));
                                Storage.SetBool ("log.file.enabled", false);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public override void OnLog(LogEntry l)
        {
            base.OnLog(l);

            if ( (Engine.Storage == null) || (Engine.Storage.GetBool("cli") == false) )
            {
                lock (LogEntries)
                {
                    LogEntries.Add(l);
                }
                if (FormMain != null)
                    FormMain.RefreshUi(RefreshUiMode.Log);

                if (FormMain == null) // Otherwise it's showed from the RefreshUI in the same UI Thread
                {
                    if (l.Type == LogType.Fatal)
                    {
                        MessageBox.Show(FormMain, l.Message, Constants.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        public void Log(LogEntry l)
        {
            string msg = l.Message;

            TableLogsController.AddLog (l);

            if ((msg != "") && (l.Type != LogType.Verbose)) {
                if(Engine.IsConnected() == false)
                {
                    Window.Title = Constants.Name + " - " + msg;
                    MnuTrayStatus.Title = "> " + msg;
                }
            }

            if (l.Type >= LogType.InfoImportant) {
                StatusItem.ToolTip = msg;
                if(Engine.Instance.Storage.GetBool("gui.osx.sysbar.show_info"))
                    StatusItem.Title = msg;
            }

            if (l.Type >= LogType.InfoImportant)
                Notification (msg, "");

            if (l.Type >= LogType.InfoImportant)
                RequestAttention ();

            if (l.Type == LogType.Fatal)
                GuiUtils.MessageBox (msg);
        }
示例#5
0
        public void Log(LogEntry l)
        {
            if (this.InvokeRequired)
            {

                LogDelegate inv = new LogDelegate(this.Log);

                this.BeginInvoke(inv, new object[] { l });
            }
            else
            {
                lock (this)
                {
                    string Msg = l.Message;

                    if (l.Type > LogType.Realtime)
                    {
                        ListViewItemLog Item = new ListViewItemLog();
                        Item.ImageKey = l.Type.ToString().ToLowerInvariant();
                        Item.Text = "";
                        Item.SubItems.Add(l.GetDateForList());
                        Item.SubItems.Add(l.GetMessageForList());
                        Item.ToolTipText = l.Message;
                        Item.Info = l;

                        lstLogs.Items.Add(Item);
                        Item.EnsureVisible();

                        if (lstLogs.Items.Count >= Engine.Storage.GetInt("gui.log_limit"))
                            lstLogs.Items.RemoveAt(0);
                    }

                    if ((Msg != "") && (l.Type != LogType.Verbose))
                    {
                        String ShortMsg = Msg;
                        if (ShortMsg.Length > 40)
                            ShortMsg = ShortMsg.Substring(0, 40) + "...";

                        string notifyText = Constants.Name + " - " + ShortMsg;

                        if (l.Type >= LogType.InfoImportant)
                        {
                            Text = Constants.Name + " - " + Msg;
                        }

                        //if(Engine.IsConnected() == false)
                        {
                            //Text = Constants.Name + " - " + Msg;

                            mnuStatus.Text = "> " + Msg;

                            if (m_notifyIcon != null)
                            {
                                m_notifyIcon.Text = notifyText;
                                m_notifyIcon.BalloonTipText = Msg;
                                if (Engine.Storage.GetBool("gui.windows.notifications"))
                                {
                                    if (l.Type >= LogType.InfoImportant)
                                    {
                                        if (l.Type == LogType.Warning)
                                            m_notifyIcon.BalloonTipIcon = ToolTipIcon.Warning;
                                        else if (l.Type == LogType.Error)
                                            m_notifyIcon.BalloonTipIcon = ToolTipIcon.Error;
                                        else if (l.Type == LogType.Fatal)
                                            m_notifyIcon.BalloonTipIcon = ToolTipIcon.Error;
                                        else
                                            m_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
                                        m_notifyIcon.ShowBalloonTip(l.BalloonTime);
                                    }
                                }
                            }
                        }
                    }

                    if (l.Type == LogType.Fatal)
                    {
                        MessageBox.Show(this, Msg, Constants.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }
        }
示例#6
0
        public void Log(LogType Type, string Message, int BalloonTime, Exception e)
        {
            // Avoid repetition
            if (Message == m_logLast)
                return;
            m_logLast = Message;

            LogEntry l = new LogEntry();
            l.Type = Type;
            l.Message = Message;
            l.BalloonTime = BalloonTime;
            l.Exception = e;

            if (l.Type > LogType.Realtime)
            {
                m_lastLogMessage = l.Message;
                m_logDotCount += 1;
                m_logDotCount = m_logDotCount % 10;
            }

            Entries.Add(l);
            if( (Engine.Instance != null) && (Engine.Instance.Storage != null) && (Entries.Count >= Engine.Instance.Storage.GetInt("gui.log_limit")) )
                Entries.RemoveAt(0);

            if(LogEvent != null)
                LogEvent(l);

            XmlItem xml = new XmlItem("command");
            xml.SetAttribute("action", "ui.log");
            l.WriteXML(xml);
            Engine.Instance.Command(xml);

            Engine.Instance.OnLog(l);
        }
示例#7
0
        public override void OnLog(LogEntry l)
        {
            base.OnLog (l);

            lock (LogsPending) {
                LogsPending.Add (l);
            }

            OnRefreshUi (RefreshUiMode.Log);
        }