Monday, March 14, 2011

SharePoint Write Custom Error to Log file (ULS Error Logging)

Most of the requirements in sharepoint applications needs custom development i.e., web parts, workflows, event recievers, timer jobs etc.,
And we might need to write the exception/error details to log somewhere(list or text file in the file sytem).

As all the sharpoint error details are logged in 12 hive Log files, even we can write our custom error details to the same log file by using the ULS logging.
//Reference of Microsoft.Office.Server.dll needs to be added
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("My Custom Error - Message:{0} || Stack Trace:{1}", ex.Message, ex.StackTrace);
Note: the logging code statement should be run under RunWithElevatedPrivileges, if the code is executable by end user.

No comments:

Post a Comment