TraceSource.GetSupportedAttributes Method

Gets the custom attributes supported by the trace source.

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

'Declaration
Protected Friend Overridable Function GetSupportedAttributes As String()

Return Value

Type: System.String()
A string array naming the custom attributes supported by the trace source, or Nothing if there are no custom attributes.

The default implementation for GetSupportedAttributes returns Nothing.

Notes to Inheritors

When inheriting from the TraceSource class or a derived class, you can override the GetSupportedAttributes method to provide custom attributes for your class.

The following code example shows an override of the GetSupportedAttributes method to identify the custom attributes for the MyTraceSource class.

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 'New  

    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 'MyTraceSource 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft