使用XML文件记录操作日志,并从后往前读取操作日志并在richTextBox1控件中显示出来
#region 获取本地程序操作记录日志 /// <summary> /// 获取本地程序更新日志信息(由后往前读取) /// </summary> private void GetLoacalOPRecordLogInfo() { XmlDocument xmlDocGet = new XmlDocument(); xmlDocGet.Load(Application.StartupPath + @"\Log.xml"); XmlNodeList xnl = xmlDocGet.SelectNodes("/Log/LogEvent"); if (xnl != null) { for (int i = xnl.Count; i >= 0; i--) { XmlNode ChNode = (XmlNode)xnl[i]; if (ChNode != null) { if (ChNode.Name == "LogEvent") { foreach (XmlNode ChNodeChild in ChNode.ChildNodes) { switch (ChNodeChild.Name.Trim()) { case "Date": Logdate = ChNodeChild.InnerText.Trim(); //更新日期 break; case "Contact1": logContact1 = ChNodeChild.InnerText.Trim(); break; case "Contact2": logContact2 = ChNodeChild.InnerText.Trim(); break; default: break; } } } //此处添加内容到文本控件 richTextBox1.AppendText("查询日期:" + Logdate.Trim() + Environment.NewLine); richTextBox1.AppendText("查询结果:" + Environment.NewLine); richTextBox1.AppendText(" " + logContact1.ToString().Trim() + Environment.NewLine); richTextBox1.AppendText("邮件发送:" + Environment.NewLine); richTextBox1.AppendText(" " + logContact2.ToString().Trim() + Environment.NewLine); richTextBox1.AppendText("" + Environment.NewLine); richTextBox1.AppendText("************************************************************" + Environment.NewLine); } } } } #endregion