Advertisement
tankcr

Untitled

Jun 5th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11.  
  12. namespace SysTools
  13. {
  14.     public partial class LogViewer : Form
  15.     {
  16.         DataTable eventLog = new DataTable();
  17.         DataSet dataset1 = new DataSet();
  18.         public LogViewer(EventLog logs)
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void LogViewer_Load(object sender, EventArgs e)
  24.         {
  25.             EventLog currentLog = logs;
  26.             DataTable dataTable1 = new DataTable();
  27.             DataColumn column;
  28.             column = new DataColumn();
  29.             column.DataType = System.Type.GetType("System.String");
  30.             column.ColumnName = "Category";
  31.             dataTable1.Columns.Add(column);
  32.             column = new DataColumn();
  33.             column.DataType = System.Type.GetType("System.String");
  34.             column.ColumnName = "DateTime";
  35.             dataTable1.Columns.Add(column);
  36.             dataTable1.Rows.Clear();
  37.             for (int currLogIndex = 0; currLogIndex <= logs.Entries.Count; currLogIndex++)
  38.             {
  39.                 DataRow drnew = dataTable1.NewRow();
  40.                 try
  41.                 {
  42.                     EventLogEntry currLogEntry = logs.Entries[currLogIndex];
  43.                     drnew["Category"] = currLogEntry.Source;
  44.                     drnew["DateTime"] = currLogEntry.TimeGenerated;
  45.                     dataTable1.Rows.Add(drnew);
  46.                 }
  47.                 catch { }
  48.             }
  49.             dataGridView1.DataSource = dataTable1;
  50.             dataTable1.DefaultView.Sort = ("DateTime asc");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement