骄傲小公主

导航

C#写日志

   private static readonly ILog mlog = LogManager.GetLogger(typeof(Message));(命名空间log4net,需要下载log4net.dll)
  private delegate void WriteMsgHandler(string msg);

 

        public static void LogMessage(ILog mlog,  string strMsg)
        {
            mlog.Info(strMsg);
           AppendTextBoxMsg(strMsg);
        }

 public void AppendTextBoxMsg(string msg)
        {
            try
            {
                if (txtBox == null)
                {
                    txtBox = FindControl();
                }
                WriteMsgHandler wmHandler = new WriteMsgHandler(DisplayMsg);
            }
            catch(Exception ex)
            {

            }
        }
        private void DisplayMsg(string msg)
        {
            if (txtBox.Lines.Length == 3000)
            {
                txtBox.Clear();
            }
            msg = "**************" + msg + " <时间:" + DateTime.Now.ToString() + ">*************\r\n";
            txtBox.AppendText(msg);
        }

posted on 2014-07-06 10:15  骄傲小公主  阅读(123)  评论(0编辑  收藏  举报