Solved

Logging the messages on the .NET socket to the file

Posted on 2003-12-04
2
419 Views
Last Modified: 2010-04-16
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
Comment
Question by:glowas
  • 2
2 Comments
 
LVL 6

Expert Comment

by:martinv
Comment Utility
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
 
LVL 6

Accepted Solution

by:
martinv earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now