c# - Why is log4net creating an empty log file before configuration? -


my log4net creating empty log file in debug/release folders reason. example filename "(null) 20150409.txt".

i'm not sure how tell not that. programmatically configuring log4net, empty file created before configuration routine run, perhaps result of app.config file itself.

here app.config file:

<?xml version="1.0"?>     <configuration>    <configsections>     <section name="log4net" type="log4net.config.log4netconfigurationsectionhandler,log4net"/>   </configsections>    <log4net>     <root>       <level value="all"/>       <appender-ref ref="logfileappender"/>     </root>     <appender name="logfileappender" type="log4net.appender.rollingfileappender, log4net">       <!--http://logging.apache.org/log4net/release/config-examples.html-->       <!--http://logging.apache.org/log4net/release/faq.html-->        <!--<param name="file" value="c:\images\log-file.txt" />-->       <file type="log4net.util.patternstring" value="%property{logfilename}"/>        <staticlogfilename value="false"/>       <param name="appendtofile" value="true"/>       <rollingstyle value="date"/>       <datepattern value="' 'yyyymmdd'.txt'"/>       <layout type="log4net.layout.patternlayout">         <param name="conversionpattern" value="%date [%thread] %-5level %logger [%property{ndc}] - %message%newline"/>       </layout>     </appender>   </log4net>    <startup uselegacyv2runtimeactivationpolicy="true">     <supportedruntime version="v4.0" sku=".netframework,version=v4.5"/>   </startup>  </configuration> 

here c# configuration code (which appears work fine):

log4net.globalcontext.properties["logfilename"] = logfilename;   // full path log file log4net.config.xmlconfigurator.configure(); log.debug("cv3 launched log file located here: " + logfilename); 

how prevent empty file being created without affecting rest of logging working fine?

i have same problem. doing research around (here, here , here), error because have called log4net.config.xmlconfigurator.configure(); before setting log4net properties.

if me, have configured log4net time in file assemblyinfo.cs. because logger in assemblyinfo loaded first, create (null) file every time app start.

hope helps.


Popular posts from this blog