I am a big fan of exhausting OOTB functionality at all levels in any platform. Simply put reuse saves a lot of time! SharePoint is no exception, in fact it has a really rich code base. I have seen a lot of developers adding custom logging components to their SharePoint dev projects. It’s almost impossible to work with Event Handlers, Features, Workflows and some Web Parts without logging error messages at runtime.

I myself have been guilty in the past of this practice, but today I found a quick and easy way to log errors using the build in logging functionally.

Here’s the one liner, I am sure you will love it:

catch(Exception Ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception Occurred: {0} || {1}", Ex.Message, Ex.StackTrace);
}

Tip to self: Use <Code> blocks to encapsulate code for proper rendering, finally figured how this worked in Word Press.

Advertisements