logging and emulator

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I am using log4net in my cf project. I am able to log to a file but I
would like to view the log in a bigger desktop window. I was thinking
about using a udp appender in log4net and then write a little program
on the desktop that listened to the logs. Is this a good idea? Has
anyone else used this method? Is there something else that might
accomplish the same thing? What is everyone else doing?

Rob
 
Rob said:
I am using log4net in my cf project. I am able to log to a file but I
would like to view the log in a bigger desktop window. I was thinking
about using a udp appender in log4net and then write a little program
on the desktop that listened to the logs. Is this a good idea?

Ofcourse, why wouldn't this be a good idea ?

I'm not sure but I think Chainsaw built from cvs (from the log4j project)
supports receiving log4net udp messages, but I guess I have some very simple
program lying around that allow you to view these messages (but you could
just as well write it yourself in about 10 lines or so) ...
anyone else used this method?

Sure, otherwise I wouldn't have created it :-)

Gert
 
Have you had any luck getting it to work with the emulator? I am able
to to use the LogFileAppender but when I try to use UDP it fails. I am
just using the sample code in the docs for the udp listener. I am using
vs2003, ppc2003 emulator, loopback adapter. I also have a lan
connection. This is my first attempt at writing udp code. What might I
be doing wrong?

Rob


============== Configuration =========================
<appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
<param name="File" value="Zlog-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<appender name="MulticastAppender" type="log4net.Appender.UdpAppender" >
<param name="RemoteAddress" value="224.168.100.2" />
<param name="RemotePort" value="11000" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="MulticastAppender" />
</root>

============== Smart Device Application Code ==========
log4net.Config.DOMConfigurator.Configure();
ILog log = LogManager.GetLogger(typeof(Form1));
if (log.IsInfoEnabled) log.Info("TEST...");
log4net.LogManager.Shutdown();


=============== LISTENER ON DESKTOP ===================
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class UDPMulticastListener
{


private static readonly IPAddress GroupAddress =
IPAddress.Parse("224.168.100.2");
private const int GroupPort = 11000;


private static void StartListener()
{
bool done = false;

UdpClient listener = new UdpClient();
IPEndPoint groupEP = new IPEndPoint(GroupAddress,GroupPort);

try
{
listener.JoinMulticastGroup(GroupAddress);
listener.Connect(groupEP);

while (!done)
{
Console.WriteLine("Waiting for broadcast");
byte[] bytes = listener.Receive( ref groupEP);

Console.WriteLine("Received broadcast from {0} :\n {1}\n",
groupEP.ToString(),
Encoding.ASCII.GetString(bytes,0,bytes.Length));
}

listener.Close();

}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

}

public static int Main(String[] args)
{
StartListener();

return 0;
}
}
 
Back
Top