Я использую PostSharp и хочу подавить (или изменить) существующий глобальный атрибут для одного метода в классе.
В приведенном ниже примере я хочу, чтобы класс «thisIsLogged()» регистрировался, а класс «thisIsNotLogged()» не регистрировался.
Однако это не работает: атрибут "[LogThis(false)]" просто добавляется к существующему атрибуту уровня класса, и логирование происходит в любом случае. Любые идеи?
[LogThis(true)] // uses PostSharp + SmartInspect to switch on logging for the entire class
class doSomething
{
void thisIsLogged(int x)
{
// entry/exit from this class is automatically logged
}
[LogThis(false)] // aim: suppress logging for this method, if [LogThis(true)] is switched on for the entire class (however, this doesn't work as attributes are additive)
void thisIsNotLogged(int x)
{
// I want to suppress the entry/exit logging for this class, to reduce log size
// However, this *doesnt work*; logging occurs anyway
// as attributes are additive - any ideas?
}
}
Изменить:
Используется [LogThis(AttributeExclude=true)], все работает нормально (см. решение ниже).