近期对原来的项目工程添加了一个test project对原工程进行nunit测试,运行msbuild后报如下错误:
log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
经查找发现原工程NHibernate中使用了
private void InitSessionFactory()
{
Configuration cfg = new Configuration();
cfg.Configure();
log4net.Config.XmlConfigurator.Configure();
sessionFactory = cfg.BuildSessionFactory();
}
在test project的app.config中并未加入与原工程web.config的log4net配置,经加入
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="c:\LogData\log.txt"/>
<param name="AppendToFile" value="false"/>
<param name="RollingStyle" value="Date"/>
<param name="DatePattern" value="yyyy.MM.dd"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n"/>
</layout>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="rollingFile"/>
</root>
</log4net>
后问题解决