成都网站建设|域名注册|虚拟主机|网站制作|网站案例|网站优化|网站推广|企业邮局|服务器租用|广告设计
// 每天一个日志文件(.XML 文件),日志的文件名称为:JobLog yyyy-MM-dd.xml string jobLogFile = AppDomain.CurrentDomain.BaseDirectory + "JobLog " + DateTime.Today.ToString("yyyy-MM-dd") + ".xml"; if (!File.Exists(jobLogFile)) t.WriteXml(jobLogFile); // 从 .XML 文件中读取日志 t.ReadXml(jobLogFile); // 添加一条日志 JobLogDataSet.JobLogRow r = t.NewJobLogRow(); r.TraceLevel = logType.ToString(); r.User = user; r.Datetime = DateTime.Now; r.Module = module; r.Function = function; r.Message = message; t.AddJobLogRow(r); // 保存到日志到 XML 文件 t.WriteXml(jobLogFile); } catch (Exception) {} } 3. 读日志的方法 /// <summary> /// 读日志 /// </summary> /// <returns>返回读取日志的 DataTable</returns> public static JobLogDataSet.JobLogDataTable ReadLog() { JobLogDataSet.JobLogDataTable jobLogDataTable = new JobLogDataSet.JobLogDataTable(); try { // 从应用程序文件夹中,获得所有日志文件 JobLog*.xml string[] jobLogFiles = Directory.GetFiles( AppDomain.CurrentDomain.BaseDirectory, "JobLog*.xml", SearchOption.TopDirectoryOnly); // 把每个日志记录读取到日志 DataTable 中 foreach (string jobLogFile in jobLogFiles) { if (File.Exists(jobLogFile)) { // 读取所有日志文件到临时 DataTable JobLogDataSet.JobLogDataTable t = new JobLogDataSet.JobLogDataTable(); t.