When we use the custom webpart and deployed to SharePoint, sometime the webpart may throw some error and administrator needs to know when and from where the error is throwing.
To log the error in SharePoint 12 hive (or SharePoint root in 2010), we need to use the following command in the catch block of the webpart/custom code.
sample code
try
{
// do something that will throw error
}
catch (Exception ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(” Error occured in Custom xyz control ” + ex.Message + ex.Source + ex.StackTrace);
}
To compile the webpart/custom code we need to include the reference assembly Microsoft.Office.Server.dll from ISAPI Folder from Sharepoint 12 hive (or Sharepoint root).
Now compile the code and deploy and when the code throws some error we can check the ULS log to get the details about the error.