Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Can't get C# program to use log4net.xml
Prev Next
You are not authorized to post a reply.

Author Messages
Paul Santa Maria

10/23/2008 2:52 AM  
Hi -

1. I'm using C# and Visual Studio 2008

2. I created a minimal C# that invokes log4net:

using log4net;
using log4net.Config;
...
    public class DeleteLogs2 {
      private static readonly ILog logger =
        LogManager.GetLogger (typeof (DeleteLogs2));
 
      static void Main (string[] args) {
        log4net.Util.LogLog.InternalDebugging = true;
        logger.Info ("Hello world");
        ...

3. I have a minimal log4net.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="FileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>
    <appender name="FileAppender"
            type="log4net.Appender.RollingFileAppender" >
            <file value="test-out.log" />
            <appendToFile value="true" />
            <rollingStyle value="Date" />
            <datePattern value=".yyyyMMdd" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d{MM/dd/yy HH:mm:ss.SSS} [%C.%M] %-5p %m%n" />
            </layout>
        </appender>

        <appender name="ConsoleAppender"
            type="log4net.Appender.ConsoleAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="[%C.%M] %-5p %m%n" />
            </layout>
        </appender>
    </log4net>
</configuration>

4. I downloaded and installed Log4net 1.2.10 (log4net.dll, from log4net-1.2.10\bin\net\2.0\release).
    I copied log4net.dll and my log4net.xml into my VS2008 project directory
    I added a reference to log4net.dll.
    It compiled without error.
    VS2008 automagically copied my log4net.xml and log4net.dll into the debug directory, along with TestLog.exe

5. I step through under the VS2008 debugger: I don't see anything written to the console, nor do I get a log file.

6. The only internal debugging output occurs *after* the last line (i.e. during program exit):
"log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]"

Does anybody have any ideas?

Ron Grabowski

10/23/2008 3:12 AM  
Your log4net.xml configuration should just contain just the log4net node:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="ConsoleAppender" />
    </root>
        <appender name="ConsoleAppender"
            type="log4net.Appender.ConsoleAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="[%C.%M] %-5p %m%n" />
            </layout>
        </appender>
    </log4net>

You have to start log4net by calling one of the Configure methods:

static void Main (string[] args) {
 XmlConfigurator.Configure(new FileInfo("log4net.xml"));
logger.Info ("Hello world");
}
Paul Santa Maria

10/23/2008 7:08 AM  

Thank you very much - adding the line you suggested fixed the problem:

  XmlConfigurator.Configure(new System.IO.FileInfo("log4net.xml"));:

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Can't get C# program to use log4net.xml



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement