namespace Com.Foo
{
public class Bar
{
private static readonly ILog log = LogManager.GetLogger(typeof(Bar));
public void DoIt()
{
log.Info("Did it again!");
}
}
}
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
string sfile = @"C:\development\Framework\Logging\ConsoleApplication1\app.config";
XmlConfigurator.Configure(new System.IO.FileInfo(sfile));
log.Info("Entering application.");
Bar bar = new Bar();
bar.DoIt();
log.Info("Exiting application.");
Console.ReadLine();
}
}
我的 log4net 配置如下所示:
<!-- A1 is set to be a ConsoleAppender -->
<appender name="A1" type="log4net.Appender.ConsoleAppender">
<!-- A1 uses PatternLayout -->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" />
</layout>
</appender>
<!-- Set root logger level to DEBUG and its only appender to A1 -->
<root>
<level value="DEBUG" />
<appender-ref ref="A1" />
</root>
<!-- Print only messages of level WARN or above in the package Com.Foo -->
<logger name="Com.Foo">
<level value="WARN" />
</logger>
我的应用程序的输出仍然显示来自 Com.Foo 的日志
67 [10] INFO ConsoleApplication1.Program (null) - 进入应用程序。
100 [10] INFO ConsoleApplication1.Com.Foo.Bar (null) - 又来了!
100 [10] INFO ConsoleApplication1.Program (null) - 退出应用程序。
如何配置 Com.Foo.Bar 停止显示为 WARN 级别?
我错过了什么?
谢谢