However, there are couple very serous considerations we have to take into account. First, Event Log must be run under very strict security framework. Second, Event Log is process intensive operation. Finally, Event Log can throw exceptions if Event Log is filled. Event log should be avoided with partial trust assemblies.
In order to create Event Log and write to it we need to use EventLog class.
public static void CreateEventLog()
EventLog DemoLog = new EventLog("Demo");
DemoLog.Source = "Demo";
DemoLog.WriteEntry("CreateEventLog call", EventLogEntryType.Information);
This will crate an entry in our list of Event Logs.
If we want to remove Event Log that we just created we’ll do it the following way
public static void DeleteEvantLog()
EventLog is also useful to work with Built-in Event Logs such as Application Log, Security Log and System Log.
Example of writing to Event Log
public static void WriteToApplicationEventLog()
EventLog DemoLog = new EventLog("Application");
DemoLog.Source = "DemoApp";
DemoLog.WriteEntry("Written to Application Log", EventLogEntryType.Information);
Reading from Event Log is very important if we try to display errors or failed attempt to run application to the web. We can do this using following code.
public static void ReadEventLog()
EventLog MyDemoLog = new EventLog();
MyDemoLog.Log = "Demo";
foreach (EventLogEntry MyDemoEntry in MyDemoLog.Entries)
Console.WriteLine(MyDemoEntry.Source + ":" + MyDemoEntry.Message);
Clearing Log is even simpler.
public static void ClearEventLog()
EventLog MyLogDemo = new EventLog("Demo");
MyLogDemo.Source = "DemoApp";