Using log4net as a class library?

I work with a console application with C #, visual studio 2008, .net framework 3.5, Windows 7. I created the log4net library and plan to use it in several projects on my solution.

This is what my log4net library class looks like:

public class LibraryLogClass1
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public static void Method3(string message)
    {
        log.Debug(message);
    }
}

In my main console project, I have the following:

   class Program
    {

        static void Main(string[] args)
        {
            LibraryLog3.LibraryLogClass1.Method3("test3");
        }
    }

I added this line to my AssemblyInfo.cs in my console project:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

This is my App.config in my console project:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="LogFileAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
      <file value="C:\test3.txt"/>
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %c %m%n" />
      </layout>
    </appender>
  </log4net>
</configuration>

When the program starts, the file is not created.

How can i solve this?

thank

+4
source share
1 answer

If you look at the log4net documentation for assembly attributes , it says the following:

", , log4net . LogManager.GetLogger . , , . "

3 , , .

- :

LogManager.GetLogger("Initialise log4net from the current assembly attributes");
+3

All Articles