Link to home
Start Free TrialLog in
Avatar of glowas
glowas

asked on

Logging the messages on the .NET socket to the file

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?
Avatar of martinv
martinv
Flag of Czechia image

Maybe properly configured packet sniffer program can be helpfull. You can use the packet sniffing library on the second thread for monitoring purposes.

Try to look at c# opensource packet sniffer library and ui:

http://www.prism.gatech.edu/~gte477n/languages/csharp/
http://www.prism.gatech.edu/~gte477n/languages/csharp/netsniffer.html

ASKER CERTIFIED SOLUTION
Avatar of martinv
martinv
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial