Solved

Logging the messages on the .NET socket to the file

Posted on 2003-12-04
2
424 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
ID: 9901197
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
ID: 9901219
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS subreport with parameter 3 46
Getting error in connectionstring with Excel. 30 45
Please explain purpose of GZIP 4 34
need to convert function to c# 5 23
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 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