共用方式為


SourceFilter(String) 建構函式

定義

初始化類別的新實例 SourceFilter ,指定追蹤來源的名稱。

public:
 SourceFilter(System::String ^ source);
public SourceFilter(string source);
new System.Diagnostics.SourceFilter : string -> System.Diagnostics.SourceFilter
Public Sub New (source As String)

參數

source
String

追蹤源的名稱。

範例

以下程式碼範例使用兩個不同的來源過濾器呼叫此 TraceData 方法,一個為虛構名稱,另一個為目前追蹤來源名稱。 第一種情況下,追蹤不會寫入主控台;在第二種情況下,trace 是寫入的。 此程式碼範例是本類別更大範例 TraceSource 的一部分。

// Test the filter on the ConsoleTraceListener.
ts.Listeners["console"].Filter = new SourceFilter("No match");
ts.TraceData(TraceEventType.Information, 5,
    "SourceFilter should reject this message for the console trace listener.");
ts.Listeners["console"].Filter = new SourceFilter("TraceTest");
ts.TraceData(TraceEventType.Information, 6,
    "SourceFilter should let this message through on the console trace listener.");
' Test the filter on the ConsoleTraceListener.
ts.Listeners("console").Filter = New SourceFilter("No match")
ts.TraceData(TraceEventType.Information, 5, "SourceFilter should reject this message for the console trace listener.")
ts.Listeners("console").Filter = New SourceFilter("TraceTest")
ts.TraceData(TraceEventType.Information, 6, "SourceFilter should let this message through on the console trace listener.")

備註

參數的 source 值用來初始化屬性 Source

適用於