SPDiagnosticsServiceBase.WriteTrace method

Writes a trace to the Microsoft SharePoint Foundation trace log.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Public Sub WriteTrace ( _
	id As UInteger, _
	category As SPDiagnosticsCategory, _
	severity As TraceSeverity, _
	output As String, _
	ParamArray data As Object() _
Dim instance As SPDiagnosticsServiceBase
Dim id As UInteger
Dim category As SPDiagnosticsCategory
Dim severity As TraceSeverity
Dim output As String
Dim data As Object()

instance.WriteTrace(id, category, severity, _
	output, data)


Type: System.UInt32

The application-defined identifier for the trace.

Type: Microsoft.SharePoint.Administration.SPDiagnosticsCategory

The category of the trace.

Type: Microsoft.SharePoint.Administration.TraceSeverity

The severity of the trace.

Type: System.String

The message. Optionally, the message may contain format placeholders so that the string can be passed to System.String.Format(string, Object[]) for formatting.

Type: []

The optional items to be replaced into the message format string.

You must use a category that is recognized by the service. For an example showing how to query a diagnostics services for areas and categories, see the Areas property.

Keep in mind that if you pass a value in the severity parameter that is less than the currently configured value for the category's TraceSeverity property, the trace is not written to the log.

The following example is a console application that writes a test message in the trace log.

using System;
using Microsoft.SharePoint.Administration;

namespace ConsoleApp
    class Program
        static void Main(string[] args)
            SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local;
            SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"];

            string format = "Test trace logging for category {0} in area {1}";
            diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, format, cat.Name, cat.Area.Name);

            Console.WriteLine(format, cat.Name, cat.Area.Name);