How to log errors to SharePoint Log file
When you work with share point custom code development such as Web parts, Features, Event Handlers, and Workflows etc., you can use the Sharepoint built in logging mechanism to log the errors instead of creating custom logging mechanism.
In SharePoint, log files are located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOG
To log errors/messages/exceptions to the default SharePoint log file use the following lines of code.
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(”Exception Occurred: {0} || {1}”, Exc.Message, Exc.StackTrace);
Example Code snippet:
Try
{
}
catch (Exception Exc)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(”Exception Occurred: {0} || {1}”, Exc.Message, Exc.StackTrace);
}
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
No comments yet.
Leave a comment