I want to run this UDPListener
in the background:
// launch this in a background thread
private static void UDPListen()
{
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
using( var udpClient = new UdpClient(10000))
{
while (true)
{
var buffer = udpClient.Receive(ref remoteEndPoint);
var loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
// ...
}
}
}
Can I put this inside a Task.Run()
and run it in the while()
loop?
This is how I set it up after a bit of reading and it works. Quite simple!
Asynchronous Method
The
appender
in the log4netconfig
file should be set up as something like:Synchronous Method
As appose to the
asynchronous
method above, this can be also implemented insynchronous
method in a very similar fashion: