19. ianuarie 2009 13:23
by skorpionking
0 Comentarii
Here is a handy code snippet, which shows how to write to the EventLog using C#:
string source = "MyTest";
if (!EventLog.Exists("MyLog"))
EventLog.CreateEventSource(source, "MyLog");
string info = string.Empty;
// check if there is any inner exception and log it if present
// exc is a Exception
if (exc.InnerException != null)
info = exc.Message + " [Inner Exception: " + exc.InnerException.Message + " ]"
+ " [Stack Trace: " + exc.StackTrace + " ]";
else
info = exc.Message + " [Stack Trace: " + exc.StackTrace + " ]";
EventLog.WriteEntry(source, info, EventLogEntryType.Error);
Life is good and happy coding :-)