views:

679

answers:

3

Hi I tried to configure log4net for logging everything to the console output. I have a config file nameed Log4Net.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>

and I have my main class (just a testing case)

namespace TestLog4Net {
    class Program {
        private static readonly ILog log = LogManager.GetLogger(typeof(Program));

        static void Main(string[] args) {
            log.Info("Info");
            log.Error("Error");
            Console.ReadKey();
        }
    }
}

I added these lines to the AssemblyInfo.cs

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

But now nothing is logged, can someone explain this?

Thanks in advance

Sebastian

A: 

ConsoleAppender appends log events to the standard output stream:

http://logging.apache.org/log4net/release/sdk/log4net.Appender.ConsoleAppender.html

Kobi
Yes I know, sorry, i just found a solution I just put all the config stuff in the app.config. This solved the problem
Xelluloid
+6  A: 

When you have log4net config in a separate config file you should not include the configuration and configSections elements. log4net should be the top level element after the xml declartion.

Peter Lillevold
+1  A: 

try this way. worked for me..

string logFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\Config\\Log4Net.config";
    FileInfo finfo = new FileInfo(logFilePath);
   log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo); 

i know very late reply. but will be useful for some one right.

NiTRiX-Reloaded