Thursday, January 29, 2009

Event logging Extension Method

This was my best URL for eventing:
http://aspalliance.com/987_Event_Logging_in_a_NET_Web_Service.all

I took it to another level and added a LINQ'like Extension Method for strings:

public static class StringToEvent
{
public static void WriteEventLog(this string logEntry, EventLogEntryType entryType)
{
// use EventLog to call WriteEntry
using (EventLog eLog = new EventLog("Application", "greenriver", "MyApp"))
{
// write to (Application) event log
eLog.WriteEntry(logEntry, entryType, 1000);
}
}
}

NOTE: you must have the following registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MyApp

No comments:

Post a Comment