Wednesday, September 30, 2009

Create log - first option in Event Viewer

Hi,

There are several options for writing logs

1. Create log in event viewer
2. Create log in file
3. Create log in entity log

Here is an example of writing log in event viewer


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace WriteToEventLog {
class Program {
static void Main(string[] args) {
string eventViewerName = "EventViewerName";
string sourceName = "Project name";
string message = "My Message";

if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, eventViewerName);

EventLog.WriteEntry(sourceName, message);
EventLog.WriteEntry(sourceName, message, EventLogEntryType.Warning, 1100);
EventLog.WriteEntry(sourceName, message, EventLogEntryType.Error,45454);
}
}
}


Thanks
Rami Heleg.