If you are SharePoint developer or SharePoint administrator, one of important thing for your job is that face with problems of SharePoint system and give the feedback to your team or correct it as soon as possible.

As you may know, SharePoint provides 2 ways to find the reason of the problems are Windows event logs and ULS Logs.

What is ULS Logs

ULS logs is SharePoint log file which is stored in 12 hiv folder (SharePoint 2007) or 14 hiv folder(SharePoint 2010). These file can be configure to generate logs file from SharePoint Central Administration

Formerly ,I usually use Windows event log to see the reason and debugging, because it’s clear enought to get error message and searching for solution

But now, ULS logs is the first place I need to look for debugging problems. These logs normally contain the bulk of the logging information provided by SharePoint and it’s really difficult to see by text editor but you can use ULS Log Viewer to view, keep it on update and monitor these files. ULS Log Viewer is a free tool, and available now for downloading at http://archive.msdn.microsoft.com/ULSViewer. This tool allow open a log file, monitor SharePoint ULS Logs folder or open from Clipboard.

The benefit of ULS logs is that you can get more details information related to your SharePoint server than Windows event log and only SharePoint information are recorded in these files. So that you can easy to filter by status, categories, operatio, data of time range…

More than that, If you are a developer, SharePoint API allow your solution use this loggin model to through your message to both of ULS log files and Windows event logs via SharePoint Diagnostics Service. Simply, you can trace what you want like log4net library.

 SharePoint Diagnostics Service

Simply, I write the LogToULS method using SPDiagnosticsService to write the logging message as below.

private void LogToULS(string message)
{
    SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local;
    SPDiagnosticsCategory category = diagnosticsService.Areas["SharePoint Foundation"].Categories["General"];
    diagnosticsService.WriteTrace(99, category, TraceSeverity.High, message, null);
}

As you see, WriteTrace method have some input parameters:

  • The first one is an ID, you can put any number for this parameter
  • The second one is the category we retrieved from the second line
  • The third one is the severity of this log entry message and it’s defined by  TraceSeverity enumeration
  • And your message need to be logged
Hope it’s help!
Hoang Nhut Nguyen
Email: nhutcmos@gmail.com
Skype: hoangnhut.nguyen