Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace GetLogs
- {
- public class Eventlogs
- {
- string eventLog;
- public string EventLog
- {
- get { return eventLog; }
- set { eventLog = value; }
- }
- public Eventlogs()
- {
- }
- }
- public class GetEvents
- {
- public static List<EventLog> GetEventLogs(string logtype, string computername)
- {
- //logType can be Application, Security, System or any other Custom Log.
- EventLog ev = new EventLog(logtype, computername);
- int LastLogToShow = ev.Entries.Count;
- if ( LastLogToShow <= 0 )
- Console.WriteLine("No Event Logs in the Log :" + logtype + computername);
- // Read the last 2 records in the specified log.
- int i;
- for ( i = ev.Entries.Count - 1; i>= LastLogToShow - 2; i--)
- {
- EventLogEntry CurrentEntry = ev.Entries[i];
- Console.WriteLine("Event ID : " + CurrentEntry.EventID);
- Console.WriteLine("Entry Type : " + CurrentEntry.EntryType.ToString());
- Console.WriteLine("Message : " + CurrentEntry.Message + "\n");
- }
- ev.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement