Pages

Friday, July 24, 2009

How to write error message to SharePoint logs file

SharePoint object model gives us very good functionality and ability to write our customize error messages into SharePoint logs file.

We can pass our error string into LogString method from Microsoft.Office.Server.Diagnostics.PortalLog class and it will write error into logs file.

Sample Code:

try

{

//CODE

}

catch (Exception Ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception – {0} – {1} – {2}" , "Sharepoint Application Name" , Ex.Message , Ex.StackTrace);

}

Catch the errors!!!

No comments:

Post a Comment