TraceSource.GetSupportedAttributes 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得由追蹤來源所支援的自訂屬性。
protected:
virtual cli::array <System::String ^> ^ GetSupportedAttributes();
protected public:
virtual cli::array <System::String ^> ^ GetSupportedAttributes();
C#
protected virtual string[]? GetSupportedAttributes ();
C#
protected virtual string[] GetSupportedAttributes ();
C#
protected internal virtual string[] GetSupportedAttributes ();
abstract member GetSupportedAttributes : unit -> string[]
override this.GetSupportedAttributes : unit -> string[]
Protected Overridable Function GetSupportedAttributes () As String()
Protected Friend Overridable Function GetSupportedAttributes () As String()
String[]
字串陣列,由追蹤來源支援的自訂屬性。如果沒有自訂屬性,則為 null
。
下列程式代碼範例示範 方法的 GetSupportedAttributes 覆寫,以識別 類別的 MyTraceSource
自定義屬性。
C#
public class MyTraceSource : TraceSource
{
string firstAttribute = "";
string secondAttribute = "";
public MyTraceSource(string n) : base(n) {}
public string FirstTraceSourceAttribute
{
get {
foreach (DictionaryEntry de in this.Attributes)
if (de.Key.ToString().ToLower() == "firsttracesourceattribute")
firstAttribute = de.Value.ToString() ;
return firstAttribute;
}
set { firstAttribute = value; }
}
public string SecondTraceSourceAttribute
{
get {
foreach (DictionaryEntry de in this.Attributes)
if (de.Key.ToString().ToLower() == "secondtracesourceattribute")
secondAttribute = de.Value.ToString();
return secondAttribute; }
set { secondAttribute = value; }
}
protected override string[] GetSupportedAttributes()
{
// Allow the use of the attributes in the configuration file.
return new string[] { "FirstTraceSourceAttribute", "SecondTraceSourceAttribute" };
}
}
Public Class MyTraceSource
Inherits TraceSource
Private firstAttribute As String = ""
Private secondAttribute As String = ""
Public Sub New(ByVal n As String)
MyBase.New(n)
End Sub
Public Property FirstTraceSourceAttribute() As String
Get
Dim de As DictionaryEntry
For Each de In Me.Attributes
If de.Key.ToString().ToLower() = "firsttracesourceattribute" Then
firstAttribute = de.Value.ToString()
End If
Next de
Return firstAttribute
End Get
Set(ByVal value As String)
firstAttribute = value
End Set
End Property
Public Property SecondTraceSourceAttribute() As String
Get
Dim de As DictionaryEntry
For Each de In Me.Attributes
If de.Key.ToString().ToLower() = "secondtracesourceattribute" Then
secondAttribute = de.Value.ToString()
End If
Next de
Return secondAttribute
End Get
Set(ByVal value As String)
secondAttribute = Value
End Set
End Property
Protected Overrides Function GetSupportedAttributes() As String()
' Allow the use of the attributes in the configuration file.
Return New String() {"FirstTraceSourceAttribute", "SecondTraceSourceAttribute"}
End Function 'GetSupportedAttributes
End Class
預設實作會 GetSupportedAttributes 傳 null
回 。
從 TraceSource 類別或衍生類別繼承時,您可以覆寫 GetSupportedAttributes() 方法,以提供類別的自定義屬性。
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |