1

I'm struggling with Log4Net for a good while now. I have followed this post as an example. The difference is, in my case, I have two separate projects, one with all objects that interacts with WebDriver and web elements (FrameworkProject), second is actual test project(TestProject). I have read a lot and I'm almost sure I have set it correctly... FrameworkProject assembly file includes [assembly: log4net.Config.XmlConfigurator(Watch = true)]

My Log4Net.config file is as follow:

    <configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <log4net>
    <root>
      <level value="ALL" />
      <appender-ref ref="MyAppender" />
      <appender-ref ref="MyFileAppender" />
    </root>
    <appender name="MyAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="MyFileAppender" type="log4net.Appender.FileAppender">
      <file value="application.log" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level %logger - %message%newline" />
      </layout>
    </appender>
  </log4net>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

</configuration>

When I debug my SpecFlow tests and I reach the line XmlConfigurator.Configure(); (look example above) I'm still getting

log4net:ERROR Failed to find configuration section 'log4net' in the application's. 

This drops me mad now and I have no clue of what might be wrong. Could this be the cause of running test?? Note: I have log4net set up ONLY in FrameworkProject

Community
  • 1
  • 1
Jakubee
  • 634
  • 1
  • 9
  • 30

1 Answers1

1

I have log4net set up ONLY in FrameworkProject

That's the problem. Roughly speaking, your "entry point" during test execution is your Test Project, hence it's looking for log4net configuration section inside of "entry point's" application configuration file (Test Project's app.config). Thus you should move your log4net configuration to Test Project's application configuration file.


On a second notice, it looks like you don't need to call XmlConfigurator.Configure if you use assembly level attribute: 1, 2.

Community
  • 1
  • 1
Yurii
  • 4,811
  • 7
  • 32
  • 41
  • Ok, I have no idea why I just didn't tried to do it way earlier...Anyway, I did as you proposed. I have copied log4net section to my App.config file. Added an configuration to assembly. Now, when I run it nothing happens... – Jakubee Jul 20 '16 at 16:38
  • The [assembly:...] statement is needed in the entry-point project – Jeroen Heier Jul 20 '16 at 18:13
  • Got this working. Had to do bit more googling... also, I didn't noticed the application.log file being actually created in lib\debug folder... I mark this as solution as it pointed me to right direction. Thanks! – Jakubee Jul 21 '16 at 09:03