Programatically create Event Log entry

Using EventLog class you can easily create Event Log entry in your application.Here is the Code:

if (!EventLog.SourceExists("LogName"))
{
EventSourceCreationData objEventSourceCreationData = new EventSourceCreationData("LogName", "Display Event Log Name in Event Viewer");
EventLog.CreateEventSource(objEventSourceCreationData);
}
ErrorLogger.LogError("LogName", message, System.Diagnostics.EventLogEntryType.Information);

you need to replace "LogName" with your appropriate message.

Happy coding...

No comments:

Post a Comment