kamagra how much to take

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:

  1. 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); });
Share

5 Comments

  1. Jim says:

    Presumably this is why we have had issues using Log4Net to consistently log to the system event logs too…

  2. Peter says:

    So this assumes that you don’t want to write to the ULS logs? I’ve seen people mention doing that, but never heard of SharePoint apps writing to the system event log. I can see the obvious benefits of the event log over the ULS logs (ULS logs recycle QUICK), but would you recommend the system log categorically? Would you ever recommend writing to the ULS log?

    I’m just curious.

  3. Adam Buenz says:

    Jim:

    Yup, I am pretty sure this is why we where having problems with it.

    Peter:

    There are indeed particular things that I choose to log to the ULS, it commonly depends on whom I expect to check for and ultimately settle the error. It is problematic to distinguish uniformly however because I believe that it breaks down to your overall project team structure, where responsibilities lie for the production environment, and organizational culture in aggregate Generally though, I try to reserve the event log for architectural events that usually I expect the operations end of the house to troubleshoot, rarely using it for informational messages that I find instead more helpfully place in the ULS logs for example.

    I am going to think about this more though…

    :)

  4. Peter says:

    Cool, I had just assumed up to this point everyone was logging into the ULS logs, it hadn’t occurred to me that anywhere else was an option.

  5. Gaurav says:

    Indeed this is an helpful post.Good Food for thought for why to write to Event Log.

Trackbacks/Pingbacks

  1. Links (5/27/2008) « Steve Pietrek - Everything SharePoint - [...] Remember to Elevate For Event Log Entries [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>