Solved

Logging the messages on the .NET socket to the file

Posted on 2003-12-04
2
421 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
which object should i use (efficiency) 5 45
How to Get total minutes between two hours 4 44
WKHTMLTOPDF - --disable-smart-shrinking not working 10 35
DateTimepicker 4 33
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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

19 Experts available now in Live!

Get 1:1 Help Now