Question

I have an Log4Net configuration that produces output as expected in a console application.

I have the exact same config, and invokation code (all done at the earliest point possible in the execution flow), but in the context of NUnit tests.

I know the configuration is loaded correctly. Additionally, I have turned the system diagnostics for Log4Net, and the debug prints are the exact same in both cases.

In the console application the text gets written. Otherwise, the file is empty.

The configuration code:

<log4net>
<!--APPENDERS-->    
<!--Endpoint File Appender-->
<appender name="EndpointFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="C:\Temp\Endpoint.log" />
  <appendToFile value="true" />
  <maximumFileSize value="100KB" />
  <maxSizeRollBackups value="10" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message" />
  </layout>
</appender>
<!--LOGGERS-->   
<logger name="EndpointLog">
  <level value="ALL" />
  <appender-ref ref="EndpointFileAppender" />
</logger>

The Invocation code (first thing at application boot):

log4net.Config.XmlConfigurator.Configure();
ILog log = LogManager.GetLogger("EndpointLog");
log.Info("Hello World.");

Any ideas? Thanks

No correct solution

OTHER TIPS

Is it that you need a root section? Try adding this:

<root>
  <level value="All" />
  <appender-ref ref="EndpointFileAppender" />
</root>

When you are running in an unittest context, you need to copy the log4net config into the bin folder with your unittest dlls. You can do this by setting copy tot output folder on the log4net config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top