Example #1
0
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="EnumLogType"></param>
        /// <param name="logContent"></param>
        public void AddLog(EnumLogCategory logcate, EnumLogType EnumLogType, string logContent)
        {
            if (this.lastLogContent == logContent)
            {
                return;
            }

            if (showLog == true)
            {
                if (this.ListView_Log.InvokeRequired)
                {
                    AddLogInvoke addLogInvoke = new AddLogInvoke(AddLog);
                    this.Invoke(addLogInvoke, new object[3] {
                        logcate, EnumLogType, logContent
                    });
                }
                else
                {
                    ListViewItem viewItem = new ListViewItem();
                    if (EnumLogType == EnumLogType.错误)//错误用红色显示
                    {
                        viewItem.BackColor = Color.Red;
                    }
                    viewItem.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    viewItem.SubItems.Add(logContent);
                    viewItem.ToolTipText = logContent;
                    viewItem.SubItems.Add(logcate.ToString());
                    viewItem.SubItems.Add(EnumLogType.ToString());
                    viewItem.ImageIndex = 0;
                    this.lastLogContent = logContent;
                    if (this.cb_LogType.Text == EnumLogType.ToString() || this.cb_LogType.Text == EnumLogType.所有.ToString())
                    {
                        this.ListView_Log.Items.Add(viewItem);
                        this.ListView_Log.Items[this.ListView_Log.Items.Count - 1].EnsureVisible();
                        if (this.ListView_Log.Items.Count > 200)
                        {
                            this.ListView_Log.Items.RemoveAt(0);
                        }
                    }
                    Application.DoEvents();

                    //modify by zwx,防止重复添加日志到数据库
                    //OnSaveLog(logcate, EnumLogType, logContent);
                }
            }
            //else
            //{
            //    OnSaveLog(logcate, EnumLogType, logContent);
            //}
        }
Example #2
0
        public void AddLogErrorCode(EnumLogCategory logcate, EnumLogType EnumLogType, string logContent, int errorCode)
        {
            if (this.lastErrorLogContent == logContent)
            {
                return;
            }

            if (showLog == true)
            {
                if (this.ListView_Log.InvokeRequired)
                {
                    AddErrorLogInvoke addErrorLogInvoke = new AddErrorLogInvoke(AddLogErrorCode);
                    this.Invoke(addErrorLogInvoke, new object[4] {
                        logcate, EnumLogType, logContent, errorCode
                    });
                }
                else
                {
                    ListViewItem viewItem = new ListViewItem();
                    if (EnumLogType == EnumLogType.错误)//错误用红色显示
                    {
                        viewItem.BackColor = Color.Red;
                    }
                    viewItem.SubItems.Add(DateTime.Now.ToString());
                    viewItem.SubItems.Add(logContent);
                    viewItem.ToolTipText = logContent;
                    viewItem.SubItems.Add(logcate.ToString());
                    viewItem.SubItems.Add(EnumLogType.ToString());
                    viewItem.SubItems.Add(errorCode.ToString());
                    viewItem.ImageIndex      = 0;
                    this.lastErrorLogContent = logContent;
                    if (this.cb_LogType.Text == EnumLogType.ToString() || this.cb_LogType.Text == EnumLogType.所有.ToString())
                    {
                        this.ListView_Log.Items.Add(viewItem);
                        this.ListView_Log.Items[this.ListView_Log.Items.Count - 1].EnsureVisible();
                        if (this.ListView_Log.Items.Count > 200)//保留200条日志
                        {
                            this.ListView_Log.Items.RemoveAt(0);
                        }
                    }
                    Application.DoEvents();
                    //OnSaveErrorLog(logcate, EnumLogType, logContent, errorCode);
                }
            }
            //else
            //{
            //    OnSaveErrorLog(logcate, EnumLogType, logContent, errorCode);
            //}
        }