Remember to Elevate For Event Log Entries

Remember if you are logging errors to the system event log when developing your SharePoint application code you need to commonly promote the privileges that it is occurring under. Below is a common line that you can use in your catch blocks that gives you pretty much all the information you could want about an exception object:

[csharp] SPSecurity.RunWithElevatedPrivileges(delegate { EventLog.WriteEntry(Your WebPart Name, string.Concat(new object[] { “Exception in Function: “, ex.Message, ” Inner Excpetion: “, ex.InnerException, “Call Stack: “, ex.StackTrace }), EventLogEntryType.Error); });
[/csharp]

Share