Event log

There are times when you want to log messages to describe current status of our application. During development, you may log events to assist in debugging complex problems. For applications that have no user interface, such as Windows services or application plug-ins, a log of events may be your only visibility of the activities performed. In live systems, event logs can help you to understand and resolve user support requests.

--> A C# Console Application


static void Main(string[] args)
{
string src;
string log;
string eve;
EventLog el = new EventLog();
src = "Sample .Net Console Application";
log = "Application";
eve = "Samples";
//you need to clear your logs in order view new one,. due to space
el.Log = "Application";
el.Clear();
if(!(EventLog.SourceExists(src)))

EventLog.CreateEventSource(src, log);


EventLog.WriteEntry(src,eve);
EventLog.WriteEntry(src,eve,EventLogEntryType.Warning,234);

foreach (EventLog objEventLog in EventLog.GetEventLogs(whichmachine))
{
eventlogs.Items.Add(new ListItem(objEventLog.LogDisplayName, objEventLog.Log)
}
}


To view your event log messages go to Start --> Control Panel --> Administrative Tool --> Event Viewer

You will see your messages there.


Comments

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:
    Email: