logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Can't get C# program to use log4net.xml
Date Thu, 23 Oct 2008 01:12:11 GMT
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");
}


----- Original Message ----
From: Paul Santa Maria <paulsm1021@yahoo.com>
To: log4net-user@logging.apache.org
Sent: Wednesday, October 22, 2008 8:52:37 PM
Subject: Can't get C# program to use log4net.xml


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?
Mime
View raw message