Event logging is a standard way for applications to record important events. Most of the windows applications log their messages, warnings and errors in event log.
Microsoft SharePoint Server, although, has it’s own centralized logging mechanism but it does not log it’s messages to event log. SharePoint LogViewer has a new feature in it’s most recent version (v2.5) to record all or few of the events in window’s event log. You can select the minimum SharePoint severity level from which the logs should be reported to event log.
In SPLV, we used System.Diagnostics.EventLog class to write messages to event log.
Following is the C# code to write log entries to event log.
string source = "Demo Application";
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, "Application");
EventLog.WriteEntry(source, "Message!", EventLogEntryType.Error);
Although, these lines of code work fine, it, however, requires the application to run under the administrator’s account otherwise it may throw a System.Security.SecurityException.
To have this feature working in SPLV, we recommend it’s users to run SPLV under the administrative privileges.