Event Viewer (C#)

Event Viewer, Event Logging from your Application

A Fast-Track Overview to Event Log


- This feature lets developer log various events to the Event Viewer repository.
- Its Namespace is System.Diagnostics
- And the Class is EventLog


using System;
using System.Diagnostics;

namespace testEventLog
class Program
static void Main(string[] args)
// Create the object of Event Log
EventLog eventLog = new EventLog( );

// Define a Source under which the Event will be logged
eventLog.Source = "MySource";

// Write a message into the Event Log repositoy
eventLog.WriteEntry("This String is written through a C# console application !!");


Compile and Run this application. It will add an event into the Event Viewer Repository.

Also refer the attached document for screen shots of Event Viewer and your event.



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: