private List <EventLogEntryDuplicate> MapSystemEventLogEntries(EventLogEntryCollection entries) { List <EventLogEntryDuplicate> eventLogEntryDuplicates = new List <EventLogEntryDuplicate>(); var enumarator = entries.GetEnumerator(); while (enumarator.MoveNext()) { EventLogEntry eventLogEntry = (EventLogEntry)enumarator.Current; eventLogEntryDuplicates.Add(new EventLogEntryDuplicate() { Category = eventLogEntry.Category, //Data = eventLogEntry.Data, CategoryNumber = eventLogEntry.CategoryNumber, EntryType = (EventLogEntryTypeDuplicate)eventLogEntry.EntryType, //Index = eventLogEntry.Index, //InstanceId = eventLogEntry.InstanceId, //MachineName = eventLogEntry.MachineName, Message = eventLogEntry.Message, //ReplacementStrings = eventLogEntry.ReplacementStrings, Source = eventLogEntry.Source, TimeGenerated = eventLogEntry.TimeGenerated, //TimeWritten = eventLogEntry.TimeWritten, UserName = eventLogEntry.UserName, }); } return(eventLogEntryDuplicates); }
/// <summary> /// 将Windows系统日志表中MedDoc内容备份到备份目录(txt格式) /// </summary> /// <returns>bool</returns> private bool BackupToTxt() { if (this.m_clsEventLog == null) { return(false); } string szBackupFile = string.Format(@"{0}\Backup\{1}.log" , this.LogFilePath, DateTime.Now.ToString("yyyyMMddHHmmss")); //连创建目录都失败,则取消写日志 if (!this.CreateFilePath(szBackupFile)) { return(false); } System.Collections.IEnumerator clsLogEnumerator = null; EventLogEntryCollection lstLogEntries = this.m_clsEventLog.Entries; StreamWriter clsFileWriter = null; try { clsFileWriter = new StreamWriter(szBackupFile, true); clsLogEnumerator = lstLogEntries.GetEnumerator(); StringBuilder sbLogInfo = new StringBuilder(); while (clsLogEnumerator.MoveNext()) { EventLogEntry clsLogEntry = (EventLogEntry)clsLogEnumerator.Current; sbLogInfo.Remove(0, sbLogInfo.Length); sbLogInfo.Append("时间:"); sbLogInfo.AppendLine(clsLogEntry.TimeGenerated.ToString()); sbLogInfo.Append("类型:"); sbLogInfo.AppendLine(clsLogEntry.EntryType.ToString()); sbLogInfo.AppendLine("日志信息:"); sbLogInfo.AppendLine(clsLogEntry.Message.ToString()); clsFileWriter.WriteLine(sbLogInfo.ToString()); clsFileWriter.WriteLine(); } sbLogInfo = null; return(true); } catch { return(false); } finally { if (clsLogEnumerator != null && clsLogEnumerator is IDisposable) { (clsLogEnumerator as IDisposable).Dispose(); } if (clsFileWriter != null) { clsFileWriter.Close(); clsFileWriter.Dispose(); } this.CloseEventLog(); } }