-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEventLogMonitor.cs
35 lines (32 loc) · 989 Bytes
/
EventLogMonitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace EventLogMonitor
{
class Program
{
static AutoResetEvent signal;
static void Main(string[] args)
{
signal = new AutoResetEvent(false);
EventLog myLog = new EventLog("Windows Powershell");
// set event handler
myLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
myLog.EnableRaisingEvents = true;
signal.WaitOne();
}
private static void OnEntryWritten(object sender, EntryWrittenEventArgs e)
{
//TextWriter writer = new StreamWriter("TEST.xml");
XmlSerializer ser = new XmlSerializer(e.Entry.GetType());
ser.Serialize(Console.Out, e);
//signal.Set();
}
}
}