Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using System.IO;
  7.  
  8. namespace BTLA
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string location = args[0];
  15.             string x = args[1];
  16.             string entryType = args[3];
  17.             int timeFrame = int.Parse(x);
  18.             StringBuilder sb = new StringBuilder();
  19.            
  20.             string logType = args[2];
  21.             //string entryType = "Information";
  22.  
  23.             EventLog ev = new EventLog(logType, Environment.MachineName);
  24.             int LastLogToShow = ev.Entries.Count;
  25.  
  26.             if (LastLogToShow <= 0)
  27.                 Console.WriteLine("No Event Logs in Log: " + logType);
  28.  
  29.             foreach (EventLogEntry e in ev.Entries)
  30.             {
  31.                 if (e.EntryType.ToString() == entryType)
  32.                 {
  33.                     if (e.TimeGenerated > DateTime.Today.AddDays(-timeFrame))
  34.                     {
  35.  
  36.                         sb.AppendLine("Event ID2: " + e.InstanceId);
  37.                         Console.WriteLine(e.InstanceId);
  38.                         sb.AppendLine("Entry Type: " + e.EntryType.ToString());
  39.                         sb.AppendLine("Message: " + e.Message + "\n");
  40.                         sb.AppendLine(e.TimeGenerated.ToString());
  41.                         sb.AppendLine("-------------------------------------------------------------------------");
  42.                         Console.WriteLine(e);
  43.                     }
  44.  
  45.                 }
  46.             }
  47.             if (location != null)
  48.             {
  49.                 Directory.CreateDirectory(location);
  50.                 Write(location);
  51.             }
  52.            
  53.  
  54.             ev.Close();
  55.  
  56.             Console.ReadLine();
  57.         }
  58.  
  59.         static void Write(string location)
  60.         {
  61.             StringBuilder sb = new StringBuilder();
  62.  
  63.             using (StreamWriter sw = new StreamWriter(location + "\\BTLA Log.txt"))
  64.             {
  65.                 sw.Write(sb.ToString());
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement