Ejemplo n.º 1
0
        void Logger_OnLog(MCP.LogEventArgs args)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new LogEventHandler(Logger_OnLog), args);
            }
            else
            {
                lock (lbLog)
                {
                    string msg1 = string.Format("[{0}]", args.LogLevel);
                    string msg2 = string.Format("{0}", DateTime.Now);
                    string msg3 = string.Format("{0} ", args.Message);
                    this.lbLog.BeginUpdate();
                    ListViewItem item = new ListViewItem(new string[] { msg1, msg2, msg3 });

                    if (msg1.Contains("[ERROR]"))
                    {
                        //item.ForeColor = Color.Red;
                        item.BackColor = Color.Red;
                    }
                    lbLog.Items.Insert(0, item);
                    this.lbLog.EndUpdate();
                    WriteLoggerFile(msg1 + msg2 + msg3);
                    InsertDataLog(args.LogLevel.ToString(), args.Message);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Main.cs Proyecto: 0000duck/XN
        void Logger_OnLog(MCP.LogEventArgs args)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new LogEventHandler(Logger_OnLog), args);
            }
            else
            {
                lock (lbLog)
                {
                    string msg1 = string.Format("[{0}]", args.LogLevel);
                    string msg2 = string.Format(" {0}", DateTime.Now);
                    string msg3 = string.Format(" {0}", args.Message);
                    if (args.LogLevel != LogLevel.DEBUG)
                    {
                        this.lbLog.BeginUpdate();
                        ListViewItem item = new ListViewItem(new string[] { msg1, msg2, msg3 });

                        if (msg1.Contains("[ERROR]"))
                        {
                            //item.ForeColor = Color.Red;
                            item.BackColor = Color.Red;
                        }
                        lbLog.Items.Insert(0, item);
                        this.lbLog.EndUpdate();
                    }
                    WriteLoggerFile(msg1 + msg2 + msg3);
                    if (!msg1.Contains("[DEBUG]"))
                    {
                        bll.ExecNonQuery("WCS.InsertLog", new DataParameter[] { new DataParameter("@LogDate", DateTime.Now), new DataParameter("@LogType", args.LogLevel.ToString()), new DataParameter("@Info", args.Message.ToString()) });
                    }
                }
            }
        }