This log helper class seems to get used over and over again in projects I've worked on. Generally I use it as a fallback, calling it from an exception block in a application logging code. Let me know if you find it helpful.
public static class LogHelper { public static bool WriteEventLogEntry(string source, EventLogEntryType entryType, int eventId, string message) { bool passFail = true; try { if (!EventLog.SourceExists(source)) { EventLog.CreateEventSource(source, "Application"); } EventLog elog = new System.Diagnostics.EventLog(); elog.Source = source; elog.WriteEntry(message, entryType, eventId); } catch { passFail = false; //this method is usually called as a last resort, so there can be no real exception handling } return passFail; } }
Page rendered at Friday, September 03, 2010 3:17:48 AM (Mountain Daylight Time, UTC-06:00)
DisclaimerThe opinions expressed herein are just that, opinions. Don't have a fit if you think they're wrong. Post your comment or write your own blog.