This seems to do the trick if you want to log to the Windows event log:
private void logError(string message, string source)
{
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = source;
log.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error);
log.Close();
}
private void logError(Exception exception, string source)
{
logError(exception.ToString(), source);
}
Put it in your class, or in a special logging class.
Read more:
- http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=77
- http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx
I might add that the comment about latency when creating event log sources does not seem to apply on Windows 2008 Server (where I tested the above code – which doesn’t even create a source… ummm) - http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx
| Internt/Egna | SharePoint – Miniprojekt | Utveckling/Design | Lookup fält programmagiskt… / ContentTypes |