Using the Trace Logging API
Published: May 2010
This topic provides information on the new Trace Logging API in Microsoft SharePoint Foundation 2010.
In Windows SharePoint Services 3.0, the only way that developers could write to the event logs was to implement the IDiagnosticsManager interface and use the Trace Log writing methods there. However, in Microsoft SharePoint Foundation 2010 the preferred method of writing to the Trace Logs is to use the class, specifically the WriteTrace() and methods.
Unlike Windows SharePoint Services 3.0, custom categories do not need to be defined in order to write to the logs. Instead, passing a parameter to the WriteTrace() and methods will allow a category to be injected into the log.
Writing to the Trace Log
This example shows how to use the object model to write directly to the Trace Log.
using Microsoft.SharePoint.Administration; WriteTrace(System.UInt32, Microsoft.SharePoint.Administration.SPDiagnosticsCategory, Microsoft.SharePoint.Administration.TraceSeverity, System.String, System.Object);
For more information, see SPDiagnosticsServiceBase.
Writing to the Event Log
This example shows how to use the object model to write directly to the event logs.
using Microsoft.SharePoint.Administration; WriteEvent(System.UInt16,Microsoft.SharePoint.Administration.SPDiagnosticsCategory,Microsoft.SharePoint.Administration.EventSeverity,System.String,System.Object);
For more information see SPDiagnosticsServiceBase.