Прочитать на английском

Поделиться через


TraceSource.GetSupportedAttributes Метод

Определение

Получает настраиваемые атрибуты, поддерживаемые источником трассировки.

protected virtual string[]? GetSupportedAttributes ();
protected virtual string[] GetSupportedAttributes ();
protected internal virtual string[] GetSupportedAttributes ();

Возвращаемое значение

String[]

Строковый массив, именующий настраиваемые атрибуты, поддерживаемые источником трассировки, или null, если настраиваемые атрибуты отсутствуют.

Примеры

В следующем примере кода показано переопределение метода для определения настраиваемых GetSupportedAttributes атрибутов для MyTraceSource класса .

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" };
    }
}

Комментарии

Реализация по умолчанию для GetSupportedAttributes возвращает null.

Примечания для тех, кто наследует этот метод

При наследовании от TraceSource класса или производного класса можно переопределить GetSupportedAttributes() метод , чтобы предоставить настраиваемые атрибуты для класса.

Применяется к