我已经为我的NSelene UI自动化项目创建了一个控制台应用程序(.Net Framework)项目。当前,我正在配置log4net。不幸的是,我无法登录到输出窗口(log4net只写到文件中)。
测试输出显示下一个错误: log4net:ERROR XmlHierarchyConfigurator:找不到名为[DebugAppender]的附加程序。 log4net:ERROR找不到名为[DebugAppender]的Appender。
我已将[assembly: log4net.Config.XmlConfigurator(Watch = true)]
添加到AssemblyInfo.cs文件中
app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<appender name="DebugAppender "
type="log4net.Appender.DebugAppender">
<immediateFlush value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] -
%m%n" />
</layout>
</appender>
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
<file value="log/SBT.UI.log"/>
<encoding value="utf-8"/>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<datePattern value="yyyyMMdd"/>
<maxSizeRollBackups value="10"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd/MM/yyyy HH:mm:ss},
%message%newline"/>
</layout>
</appender>
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] -
%m%n" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="DebugAppender"/>
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Project.cs
[SetUp]
public void Initialize()
{
logger.Debug("test1");
logger.Info("test2");
logger.Warn("test3");
logger.Error("test4");
logger.Fatal("test5");
}