给定一个类,使用属性名 MyName 扩展 FilterSkeleton ,并扩展 ApenderSkeleton
的appender是否可以获取在appender的Append方法中接受此消息的过滤器的 MyName 属性?
protected override void Append(LoggingEvent loggingEvent)
{
//sudo
var somename = acceptedfilter.MyName;
}
答案 0 :(得分:0)
您可以覆盖FilterEvent
方法以保存接受邮件的过滤器,然后在Append
中检索它:
public class FilteredAppender : AppenderSkeleton
{
private IFilter filter;
protected override bool FilterEvent(LoggingEvent loggingEvent)
{
IFilter f = this.FilterHead;
while (f != null)
{
if (f.Decide(loggingEvent) == FilterDecision.Accept)
{
filter = f; // Set the filter field
break;
}
f = f.Next;
}
return base.FilterEvent(loggingEvent);
}
protected override void Append(LoggingEvent loggingEvent)
{
NamedFilter acceptedfilter = filter as NamedFilter;
if (acceptedfilter!= null)
{
var somename = acceptedfilter.MyName;
// etc
}
}
}