#region 写操作日志----------------这种格式
//<Log 操作人="Admin" 操作结果="成功" 结果详情="数据导出成功!" 操作时间="2014/5/2714:37" />
/// <summary>
/// 写操作日志
/// </summary>
/// <param name="logInfo">要写入日志的内容</param>
/// <param name="flagOfResult">成功还是失败</param>
public static void WriteLog(string logInfo, int flagOfResult, string path)
{
try
{
if (!System.IO.Directory.Exists((path)))
System.IO.Directory.CreateDirectory(path);
string logPath = path + "Log.xml";
XmlDocument doc = new XmlDocument();
if (!File.Exists(logPath))
{
XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
doc.AppendChild(node);
//创建根节点
XmlNode root1 = doc.CreateElement("Logs");
XmlElement xe = doc.CreateElement("Log");
xe.SetAttribute("操作人", "Admin");
xe.SetAttribute("操作结果", flagOfResult == 1 ? "成功" : "失败");
xe.SetAttribute("结果详情", logInfo);
xe.SetAttribute("操作时间", DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString());
root1.AppendChild(xe);
doc.AppendChild(root1);
doc.Save(logPath);
}
else
{
doc.Load(logPath);
//查找根节点
XmlNode root = doc.SelectSingleNode("Logs");
//创建一个DataInfos节点
XmlElement xe = doc.CreateElement("Log");
xe.SetAttribute("操作人", "Admin");
xe.SetAttribute("操作结果", flagOfResult == 1 ? "成功" : "失败");
xe.SetAttribute("结果详情", logInfo);
xe.SetAttribute("操作时间", DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString());
root.AppendChild(xe);
doc.Save(logPath);
}
}
catch (Exception)
{
return;
}
}
#endregion