Share via


TraceSource.Attributes 屬性

定義

取得在應用程式組態檔中定義的自訂參數屬性。

public:
 property System::Collections::Specialized::StringDictionary ^ Attributes { System::Collections::Specialized::StringDictionary ^ get(); };
public System.Collections.Specialized.StringDictionary Attributes { get; }
member this.Attributes : System.Collections.Specialized.StringDictionary
Public ReadOnly Property Attributes As StringDictionary

屬性值

StringDictionary,其中包含追蹤參數的自訂屬性。

範例

下列程式代碼範例示範如何顯示 的 TraceSource自定義屬性。 此程式代碼範例是針對 類別提供的較大範例的 TraceSource 一部分。

// Get the custom attributes for the TraceSource.
Console.WriteLine("Number of custom trace source attributes = "
    + ts.Attributes.Count);
foreach (DictionaryEntry de in ts.Attributes)
    Console.WriteLine("Custom trace source attribute = "
        + de.Key + "  " + de.Value);
' Get the custom attributes for the TraceSource.
Console.WriteLine("Number of custom trace source attributes = " + ts.Attributes.Count)
Dim de As DictionaryEntry
For Each de In ts.Attributes
    Console.WriteLine("Custom trace source attribute = " + de.Key + "  " + de.Value)
Next de

備註

屬性 Attributes 會識別應用程式組態檔中所參考的自定義屬性。 未推斷的自定義屬性不會列舉。 繼承自 類別的 TraceSource 類別可以覆寫 Switch.GetSupportedAttributes 方法並傳回自定義屬性名稱的字串陣列來新增自定義屬性。

以下是指定自訂屬性 SecondTraceSourceAttribute的追蹤來源元素範例:

<sources>  
  <source name="TraceTest" switchName="TestSourceSwitch"   
    switchType="Testing.MySourceSwitch, TraceSample"   
    SecondTraceSourceAttribute="two">  
  </source>  
</sources>  

適用於