Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TraceFilter.ShouldTrace Method

When overridden in a derived class, determines whether the trace listener should trace the event.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public abstract bool ShouldTrace (
	TraceEventCache cache,
	string source,
	TraceEventType eventType,
	int id,
	string formatOrMessage,
	Object[] args,
	Object data1,
	Object[] data
)
public abstract boolean ShouldTrace (
	TraceEventCache cache, 
	String source, 
	TraceEventType eventType, 
	int id, 
	String formatOrMessage, 
	Object[] args, 
	Object data1, 
	Object[] data
)
public abstract function ShouldTrace (
	cache : TraceEventCache, 
	source : String, 
	eventType : TraceEventType, 
	id : int, 
	formatOrMessage : String, 
	args : Object[], 
	data1 : Object, 
	data : Object[]
) : boolean
Not applicable.

Parameters

cache

The TraceEventCache that contains information for the trace event.

source

The name of the source.

eventType

One of the TraceEventType values specifying the type of event that has caused the trace.

id

A trace identifier number.

formatOrMessage

Either the format to use for writing an array of arguments specified by the args parameter, or a message to write.

args

An array of argument objects.

data1

A trace data object.

data

An array of trace data objects.

Return Value

true to trace the specified event; otherwise, false.

Notes to Inheritors: Implementations of this method should return true if the event specified by the passed parameters should be traced. Otherwise the method should return false. For example, a filter that allows only error events to pass through to the listener should inspect the eventType parameter and return true if the trace event type level is set to TraceEventType.Error or greater; otherwise, it should return false. Implementations of the method should be prepared to handle a null reference (Nothing in Visual Basic) in the following parameters: args, data1, data, formatOrMessage, and cache. If the parameter value is a null reference (Nothing in Visual Basic), the parameter is not part of the event. For example, if the args parameter is a null reference (Nothing in Visual Basic), it means that the event does not have any arguments. If the data parameter is a null reference (Nothing in Visual Basic), then there are either one or no data objects. If there is one data object, it will be found in the data1 parameter. The reason for the distinction between a single data object and an array of data objects is for performance. There is no reason to create an object array if only one object is traced, as is normally the case. If the data parameter is not a null reference (Nothing in Visual Basic), the data1 parameter must also not be a null reference (Nothing in Visual Basic). It is guaranteed that the source parameter is not a null reference (Nothing in Visual Basic) and not an empty string (""). Implementations of the method can optionally throw the following exceptions:

The following code example shows how to override the ShouldTrace method to indicate tracing should occur when the trace event type of the event is equal to TraceEventType.Error.

public class ErrorFilter : TraceFilter
{
    public bool ShouldTrace(TraceEventCache cache, string source, 
        TraceEventType eventType, int id, string formatOrMessage,
        object[] args, object data, object[] dataArray)
        
        return eventType == TraceEventType.Error;
    }
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft