我正在使用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)],这工作正常(参见下面的解决方案)。