The SharePoint Logger

The SharePoint Guidance Library includes a basic logging and tracing component named the SharePoint logger that is tailored to the SharePoint environment. It is a reusable component that you can include in your own SharePoint applications.

Logging and tracing are different activities that produce output that is intended for two audiences. Logging is directed toward system administrators who typically rely on the Windows event logs to monitor deployed applications. They often use automated tools such as the System Center Operations Manager (SCOM) to monitor the event logs. Administrative centers are also referred to as operations.

Tracing is directed toward developers. In particular, SharePoint developers often use the Unified Logging Service (ULS) trace log. This log is used by Windows SharePoint Services itself. Logging your custom application traces to the ULS trace log allows you to view them in the larger context of Windows SharePoint Services operations without having to correlate multiple trace logs.

The SharePointLogger class provides a simple interface named ILogger. The interface includes methods that log messages based on whether they are intended for system administrators or developers. The output of the LogToOperations method is written to the event log, where it is read by system administrators. Messages for system administrators should give a clear indication of the problem and possible action that the administrator can take. These messages are also written to the trace log to help developers who may need to debug the application.

The output of the TraceToDeveloper method is only written to the trace log. Messages to the trace log are meant for developers who are familiar with the application's implementation.

To help with debugging, both methods also log additional contextual information if it is available, such as the name of the current user, the URL that was requested, and some other fields.

The SharePointLogger class should not be directly instantiated. Instead, you should use the SharePoint service locator to request it. This allows you to plug in different logging implementations. For more information about the SharePoint service locator, see The SharePoint Service Locator.

Note

The ULS trace logs can be uploaded to Microsoft as part of customer technical service and support. Do not write personal data or proprietary information to the trace log. You should not write sensitive information, such as passwords or confidential data, to any log.

This section includes the following topics.

For general guidance about logging and tracing, see Providing Application Diagnostics. For more information about the ULS trace log, see Trace Logs on MSDN.

Home page on MSDN | Community site