我尝试配置log4net以将所有内容记录到控制台输出.我有一个名为的配置文件Log4Net.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我有我的主要课程(只是一个测试案例)
namespace TestLog4Net {
class Program {
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args) {
log.Info("Info");
log.Error("Error");
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我把这些线添加到了 AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(
ConfigFile = "Log4Net.config", Watch = true)]
Run Code Online (Sandbox Code Playgroud)
但现在没有记录,有人可以解释一下吗?