4
votes

I have implemented log4net in a class library project like so:

private static readonly ILog _logger = 
        LogManager.GetLogger(typeof(SomeClass));

That's all I've done. No config file or anything.

Then in my project that references this class library, I included a log4net config section in the app.config:

<log4net>
<root>
  <level value="ALL" />
  <appender-ref ref="FileAppender"/>
</root>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
  <file value="C:/abcd.log" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  </layout>
</appender>

Now, the log4net logger in the class library project is not able to read the config from its "parent" project, so to speak.

I'm sure I need some more configuration, but I don't know where to start. There are similar questions on stackoverflow etc., but I believe they don't really give an answer on how to do this.

Your help is really appreciated.

Thanks.

1

1 Answers

6
votes

You must tell log4net where to find the logging configuration. How you do it is described in the log4net Manual.

I prefer to add [assembly: log4net.Config.XmlConfigurator(Watch=true)] to my application's AssemblyInfo.cs file.