← Back to team overview

nunit-core team mailing list archive

[Bug 605034] Re: Log4net not working with NUnit

 

** Description changed:

+ [Bug now tracked at https://github.com/nunit/nunit-framework/issues/6]
+ 
  Problem: Using log4net with newer versions of nunit means that no
  log file is created.
  
  Demonstration follows.
  
  I created the solution in VS 2008.
  The OS is Windows XP.
  I tested using both the nunit GUI and console.
  I compared Nunit 2.2.5 with 2.5.5 (I suspect 2.5.0 will fail as well.)
  The solution is created as a console app.
  
  When the app is run as a console application a Log file is produced.
  When the app is run using 2.2.5 a Log file is produced.
  When the app is run using 2.5.5 no Log file is produced.
  
  There are two files in the solution: Log.config and Program.cs
  
  Following comes from a file name "Log.config"
  
  ----------------------------------------------
  <?xml version="1.0" encoding="utf-8" ?>
- <log4net debug="false">       
+ <log4net debug="false">
  
-   <appender name="DefaultLogFile" type="log4net.Appender.RollingFileAppender">
-       <file value=".\Log" />
-       <appendToFile value="false" />
-       <staticLogFileName value="false" />           
-       <rollingStyle value="Date" />
-       <datePattern value="'.'yyyyMMdd'.log'" />
-       <layout type="log4net.Layout.PatternLayout">
-       
-         <conversionPattern value="%utcdate{ABSOLUTE} %-5level %message%newline" />
-         
-       </layout>
-   </appender>
+   <appender name="DefaultLogFile" type="log4net.Appender.RollingFileAppender">
+       <file value=".\Log" />
+       <appendToFile value="false" />
+       <staticLogFileName value="false" />
+       <rollingStyle value="Date" />
+       <datePattern value="'.'yyyyMMdd'.log'" />
+       <layout type="log4net.Layout.PatternLayout">
  
-   <root>
-     <level value="All" />
-     <appender-ref ref="DefaultLogFile" />
-   </root>
+         <conversionPattern value="%utcdate{ABSOLUTE} %-5level
+ %message%newline" />
+ 
+       </layout>
+   </appender>
+ 
+   <root>
+     <level value="All" />
+     <appender-ref ref="DefaultLogFile" />
+   </root>
  </log4net>
  -----------------------------------------------------
  
  Following is Program.cs
  
  -----------------------------------------------------
  using System;
  using System.Reflection;
  using NUnit.Framework;
  
  [assembly: log4net.Config.XmlConfiguratorAttribute(ConfigFile =
  "Log.config", Watch = true)]
  
  namespace TestNunitLog4net
  {
  [TestFixture]
  public class Program
  {
-   private static readonly log4net.ILog log 
-         = log4net.LogManager.GetLogger(
-             MethodBase.GetCurrentMethod().DeclaringType);
-             
-   // Test scenarios
-   //   Test 1: Works - log show up (gui and console)
-   //        log4net: 1.2.10.0
-   //        Nunit: 2.2.5.0
+   private static readonly log4net.ILog log
+         = log4net.LogManager.GetLogger(
+             MethodBase.GetCurrentMethod().DeclaringType);
  
-   //   Test 2: Fails - no log file (gui and console)
-   //        log4net: 1.2.10.0
-   //        Nunit: 2.5.5.10112
-   
-   // Following has no impact.
-   // It exists just so we can see it in log.
-   private readonly String exeType;
-   
-   static void Main()
-   {
-     Program p = new Program("Exe");
-     p.TestLog();
-   }
-   
-   private Program(String stype)
-   {
-     this.exeType = stype;
-   }
-   
-   public Program()
-   {
-     this.exeType = "Nunit";
-   }
+   // Test scenarios
+   //   Test 1: Works - log show up (gui and console)
+   //        log4net: 1.2.10.0
+   //        Nunit: 2.2.5.0
  
+   //   Test 2: Fails - no log file (gui and console)
+   //        log4net: 1.2.10.0
+   //        Nunit: 2.5.5.10112
  
-   [Test]
-   public void TestLog()
-   {
-     log.Debug(exeType + ": First line");
-     log.Debug(exeType + ": Second line");
-   }
+   // Following has no impact.
+   // It exists just so we can see it in log.
+   private readonly String exeType;
+ 
+   static void Main()
+   {
+     Program p = new Program("Exe");
+     p.TestLog();
+   }
+ 
+   private Program(String stype)
+   {
+     this.exeType = stype;
+   }
+ 
+   public Program()
+   {
+     this.exeType = "Nunit";
+   }
+ 
+   [Test]
+   public void TestLog()
+   {
+     log.Debug(exeType + ": First line");
+     log.Debug(exeType + ": Second line");
+   }
  
  } // End of class
  } // End of namespace
  ---------------------------------------------------------------

** Tags added: github

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/605034

Title:
  Log4net not working with NUnit

Status in NUnit Test Framework:
  Triaged
Status in NUnit V2 Test Framework:
  Fix Released

Bug description:
  [Bug now tracked at https://github.com/nunit/nunit-framework/issues/6]

  Problem: Using log4net with newer versions of nunit means that no
  log file is created.

  Demonstration follows.

  I created the solution in VS 2008.
  The OS is Windows XP.
  I tested using both the nunit GUI and console.
  I compared Nunit 2.2.5 with 2.5.5 (I suspect 2.5.0 will fail as well.)
  The solution is created as a console app.

  When the app is run as a console application a Log file is produced.
  When the app is run using 2.2.5 a Log file is produced.
  When the app is run using 2.5.5 no Log file is produced.

  There are two files in the solution: Log.config and Program.cs

  Following comes from a file name "Log.config"

  ----------------------------------------------
  <?xml version="1.0" encoding="utf-8" ?>
  <log4net debug="false">

    <appender name="DefaultLogFile" type="log4net.Appender.RollingFileAppender">
        <file value=".\Log" />
        <appendToFile value="false" />
        <staticLogFileName value="false" />
        <rollingStyle value="Date" />
        <datePattern value="'.'yyyyMMdd'.log'" />
        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%utcdate{ABSOLUTE} %-5level
  %message%newline" />

        </layout>
    </appender>

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

  Following is Program.cs

  -----------------------------------------------------
  using System;
  using System.Reflection;
  using NUnit.Framework;

  [assembly: log4net.Config.XmlConfiguratorAttribute(ConfigFile =
  "Log.config", Watch = true)]

  namespace TestNunitLog4net
  {
  [TestFixture]
  public class Program
  {
    private static readonly log4net.ILog log
          = log4net.LogManager.GetLogger(
              MethodBase.GetCurrentMethod().DeclaringType);

    // Test scenarios
    //   Test 1: Works - log show up (gui and console)
    //        log4net: 1.2.10.0
    //        Nunit: 2.2.5.0

    //   Test 2: Fails - no log file (gui and console)
    //        log4net: 1.2.10.0
    //        Nunit: 2.5.5.10112

    // Following has no impact.
    // It exists just so we can see it in log.
    private readonly String exeType;

    static void Main()
    {
      Program p = new Program("Exe");
      p.TestLog();
    }

    private Program(String stype)
    {
      this.exeType = stype;
    }

    public Program()
    {
      this.exeType = "Nunit";
    }

    [Test]
    public void TestLog()
    {
      log.Debug(exeType + ": First line");
      log.Debug(exeType + ": Second line");
    }

  } // End of class
  } // End of namespace
  ---------------------------------------------------------------

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunit-3.0/+bug/605034/+subscriptions


References