Logging the messages on the .NET socket to the file
Posted on 2003-12-04
How can I log the traffic from an application that listens on a TCP/IP socket?
By traffic I mean text messages received from and send out to the clients.
I want to log every message to a log file in order it arrives. However, I cannot block the main app from listening on its socket for new messages.
I use asynchronous framework socket functions: Socket.BeginSend and Socket.BeginReceive, so the network traffic is not blocking my app. Now I need to use asynchronous file write and read: BeginRead() and BeginWrite() methods of the Stream class.
My concern is that the messages are not going to be logged in order they arrive because the threads may not be scheduled to execute in that order.
And second how big can get the log file? What would happen with performance if the log file after a month will be 100MB.
So my question is: what is the best performing method for logging asynchronous communication on .NET socket?