You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Morten Andersen <mo...@vianett.no> on 2006/01/28 15:32:05 UTC

Is this a bug?

Create a solution with a windows application, and a class library. Add a 
project reference to to the class library, and a reference to the 
log4net.dll

If you run the application now, you should see something like 
"2006-01-28 15:18:04,556 [3028] INFO  BugApplication.MyClass [(null)] - 
Hello world" in the output window.

As you can see there are three lines that are comments. One in 
Program.cs and two in Class1.cs

If you uncomment the log line in Class1.cs, you will not see any output 
if you try to run the application.

Now there is two different solutions to make the logging work again. You 
can uncomment the log line in Program.cs, or you can uncomment the 
assembly line in Class1.cs


===============================
Windows Application (Program.cs)
===============================

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace BugApplication
{
    static class Program
    {
        //static readonly log4net.ILog log = 
log4net.LogManager.GetLogger(typeof(Program));

        static void Main()
        {
            BugClassLibrary.MyLibClass.Start(typeof(MyClass));
        }
    }

    class MyClass : BugClassLibrary.MyInterface
    {
        static readonly log4net.ILog log = 
log4net.LogManager.GetLogger(typeof(MyClass));

        public void Start()
        {
            log.Info("Hello world");
        }
    }
}

===============================
Windows Applicaton (App.config)
===============================

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>
    <log4net>
        <appender name="ConsoleAppender" 
type="log4net.Appender.ConsoleAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level 
%logger [%ndc] - %message%newline" />
            </layout>
        </appender>
        <root>
            <level value="INFO" />
            <appender-ref ref="ConsoleAppender" />
        </root>
    </log4net>
</configuration>

===============================
Class Library (Class1.cs)
===============================

//[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace BugClassLibrary
{
    public interface MyInterface
    {
        void Start();
    }

    public class MyLibClass
    {
        //static readonly log4net.ILog log = 
log4net.LogManager.GetLogger(typeof(MyLibClass));

        public static void Start(System.Type type)
        {
            ((MyInterface)System.Activator.CreateInstance(type)).Start();
        }
    }
}

===============================