Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

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?
0
glowas
Asked:
glowas
  • 2
1 Solution
 
martinvCommented:
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

0
 
martinvCommented:
As for writing logfile. Consider using some of ready-made logging packages such as log4net. They include rolling logs, which automatically stars new file when a checkpoint (such as date, file size, line numbers) is reached.

http://log4net.sourceforge.net/
http://log4net.sourceforge.net/release/latest/doc/features.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now