2

I met a strange thing in my log4net for vb.net arcmap add-in.

At first, I follow the link http://www.codeproject.com/Articles/42276/How-to-Use-Log-Net-with-VB-NET-A-Simple-Step-By-St to write logs for my arcmap add-in project. There are 2 files related to the log file:

(1) Log4NetAssembly1.exe.log4net, the configuration for log4net is:

<log4net>
<appender name="ExampleAppender" type="log4net.Appender.RollingFileAppender">
  <file value="C:\Log4NetExamples\Example.log" />
  <appendToFile value="false" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="3" />
  <maximumFileSize value="100KB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level - 
            [%logger] %message%newline" />
  </layout>
</appender>
<logger name="dev">
  <level value="ALL" />
  <appender-ref ref="ExampleAppender" />
</logger>

(2) app.config

<listeners>
    <add
        name="textWriterTraceListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="C:\Log4NetExamples\Example.log" />
  </listeners>

It works properly with log file C:\Log4NetExamples\Example.log.

Now I want to create log file daily and want each log file with the date of creation, so I updated my code as follows:

(1) Log4NetAssembly1.exe.log4net

<log4net>
<appender name="RollingLogFileAppenderOutput" type="log4net.Appender.RollingFileAppender">
  <file value="C:\Log4NetExamples\" />     
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyyMMdd'.log'" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level - 
            [%logger] %message%newline" />
  </layout>
</appender>
<logger name="dev">
  <level value="ALL" />
  <appender-ref ref="RollingLogFileAppenderOutput" />
</logger>

(2) app.config

<listeners>
    <add
        name="textWriterTraceListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="C:\Log4NetExamples" />
  </listeners>

The strange thing is after I changed to the daily logging design, my log file still written to C:\Log4NetExamples\Example.log, which means it still follow the previous configuration of log4net. I really cannot figure out why, is there anywhere remember the old configuration? I search the whole vb.net project and cannot find "Example.log" at all.

Anybody knows what happen? Please help me, thanks.

  • 1
    Perhaps it's in a registry or environment setting. Try searching for the parts where file access occurs Open, write and close could help, then find the variable and search back to where it's set. – Michael Stimson Sep 10 '14 at 2:07
  • Thanks Michael for the quick reply. Yes I forgot to change the setting in AssemblyInfo.vb. – ppLily Sep 10 '14 at 3:06
2

Thanks for the attention. I have found the reason. It is because of the setting in AssemblyInfo.vb like:

<Assembly: log4net.Config.XMLConfigurator(ConfigFile:="D:\workspace\dev_App\dev_App\Log4NetAssembly1.exe.log4net", Watch:=True)> 

Although the Log4NetAssembly1.exe.log4net name is correct, but for my case I create a new project and log4net related configuration is copied from the previous project. So the ConfigFile in AssemblyInfo.vb points to the old project path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.