6

I'm trying to get log4net to log via udp to chainsaw but its not working on windows 7. My config files are as follows:

  <log4net debug="true">
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
  <layout type="log4net.Layout.PatternLayout,log4net">
    <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
  </layout>
</appender>
<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
    <remoteAddress value="127.0.0.1" />
    <remotePort value="8085" />
    <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
      <locationInfo value="true" />
    </layout>
</appender>
<root>
  <level value="TRACE" />
  <appender-ref ref="trace" />
  <appender-ref ref="UdpAppender" />
</root>

my chainsaw config file looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">    
    <plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">
        <param name="Port" value="8085" />
    </plugin>    
</log4j:configuration>

All of this is per the documentation found in: http://logging.apache.org/log4net/release/howto/chainsaw.html

Yet none of the logs show up.

1 Answer 1

5

Figured it out. Looks like log4net has issues with ipv6 and windows 7. To get around these issues you need to add an entry into your host file that looks like this:

    127.0.0.2       localhosttwo

then your UpdAppender needs to reference that DNS entry as so:

 <remoteAddress value="localhosttwo" />

127.0.0.2 is the ipv6 address for your localmachine and you need an explcit dns entry or else log4net will throw an error if you try and use the numerical address in the config file.

Make sure to flush your dns after you change the hostfile

1
  • 1
    Thx for documenting the fix. +1. For the record, on Windows server 2012, I noticed that UdpAppender would need RemoteAddress to be set to "localhost" (which it would translate to "::1") instead of 127.0.0.1 (which it won't parse as an "IP address"). A direct way to get log4net's internal messages is to add a key in appSettings: (<add key="log4net.Internal.Debug" value="true"/>). Dec 11, 2012 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.