Click here to Skip to main content
15,915,324 members
Home / Discussions / C#
   

C#

 
AnswerRe: Number of Rows in a DataSet Table Pin
KaptinKrunch2-Dec-05 6:33
KaptinKrunch2-Dec-05 6:33 
GeneralRe: Number of Rows in a DataSet Table Pin
Jared Parsons2-Dec-05 7:09
Jared Parsons2-Dec-05 7:09 
GeneralRe: Number of Rows in a DataSet Table Pin
Drew McGhie2-Dec-05 8:27
Drew McGhie2-Dec-05 8:27 
GeneralRe: Number of Rows in a DataSet Table Pin
Jared Parsons2-Dec-05 11:31
Jared Parsons2-Dec-05 11:31 
GeneralRe: Number of Rows in a DataSet Table Pin
budidharma2-Dec-05 7:55
budidharma2-Dec-05 7:55 
QuestionFile problem exception in C#...try to writing log class Pin
Yanshof2-Dec-05 6:03
Yanshof2-Dec-05 6:03 
AnswerRe: File problem exception in C#...try to writing log class Pin
Jared Parsons2-Dec-05 7:11
Jared Parsons2-Dec-05 7:11 
AnswerRe: File problem exception in C#...try to writing log class Pin
mcljava2-Dec-05 10:40
mcljava2-Dec-05 10:40 
Jared you nailed it!

Yanshof here is some design info for ya:

When designing a Logger application here is a basic strategy to employ in your architecture. Note I highly recommend using the Async architecture to keep you application running efficiently instead of blocking all over the place. That means Stream::BeginRead, Stream::EndRead, Stream::BeginWrite, Stream::EndWrite for your cStreamWriter object, as well as Socket::BeginAccept, Socket::EndAccept, Socket::BeginReceive, and Socket::EndReceive for your socket or network stream objects.

At any rate:

Startup sequence:

Open the log file. This includes the necessary checks to determine if it exists, needs to be created, or pehaps is too large and needs to be replaced, etc. The key here is once you get the file open you need to keep it open and preserve the file stream until you are ready to shutdown or encounter a recoverable exception and restart. Also whatever stragey you employ for archiving log files and naming log files should be considered part of startup as well as part of some event based trigger, e.g, midnight, file size exceeds 1MB, etc.

Incoming Log Requests:

Decode the message, format the message, write it to the log file. Since we're talking I/O make sure you are using Try/Catch blocks in the event your file stream goes south suddenly. And here is where you would start the write with the m_cFileStream.BeginWrite() call. When the write completes the underlying driver tickles the CLR which in turn posts an IAsyncResult to your End???? handler.

A note about flushing the cache. If there is any need to flush the cache instead of leaving it up to the OS, then you should employ your threshold for flushing here. For example after every 100 messages you decide. That said there is no real need unless you can come up with one.

Timer or Event based Action:

As noted your Logger should worry about file size and rollover. Based on some timer firing, some file size grown past its threshold, or whatever, your application should take this into account. Since your application should be Async I do NOT recommend doing this in a While loop in the mainline code.

Shutdown Sequence:

OK, Here is where you close the sockets and lastly the file. In otherwords, this is the appropriate place to be calling m_cFileStream.Close(). Before you do that however make sure all client connections and Shutdown and Closed first.


Async vs. Threads

In this reponse I have advocated the Async model. But if you enjoy the threaded approach you can definitely implement a logger that way too. Suffice to say its another can of worms though.



Good Luck with it!


Mike
Questionhelp Pin
eyalso2-Dec-05 5:52
eyalso2-Dec-05 5:52 
AnswerRe: help Pin
Reanalyse2-Dec-05 21:23
Reanalyse2-Dec-05 21:23 
GeneralRe: help Pin
eyalso2-Dec-05 22:24
eyalso2-Dec-05 22:24 
QuestionUser-reorder ListViewItems by dragging? Pin
wikoh2-Dec-05 5:17
wikoh2-Dec-05 5:17 
QuestionC# out-of-process COM component Pin
london_ste2-Dec-05 4:55
london_ste2-Dec-05 4:55 
Questionwhat is the meaning of "PublicKeyToken=null is not marked as serializable." ? Pin
P. Gnana Prakash2-Dec-05 4:11
P. Gnana Prakash2-Dec-05 4:11 
AnswerRe: what is the meaning of "PublicKeyToken=null is not marked as serializable." ? Pin
[Marc]2-Dec-05 6:26
[Marc]2-Dec-05 6:26 
GeneralRe: what is the meaning of "PublicKeyToken=null is not marked as serializable." ? Pin
P. Gnana Prakash2-Dec-05 18:36
P. Gnana Prakash2-Dec-05 18:36 
QuestionHow to serialize more than one object? Pin
ishlilith2-Dec-05 3:59
ishlilith2-Dec-05 3:59 
AnswerRe: How to serialize more than one object? Pin
mav.northwind3-Dec-05 22:43
mav.northwind3-Dec-05 22:43 
QuestionUsing JPanel on Windows.Forms Pin
sbozcan2-Dec-05 3:49
sbozcan2-Dec-05 3:49 
QuestionHow to write this C code in C#? Pin
bouli2-Dec-05 2:44
bouli2-Dec-05 2:44 
AnswerRe: How to write this C code in C#? Pin
Alvaro Mendez2-Dec-05 3:29
Alvaro Mendez2-Dec-05 3:29 
GeneralRe: How to write this C code in C#? Pin
bouli2-Dec-05 3:55
bouli2-Dec-05 3:55 
AnswerRe: How to write this C code in C#? Pin
User 66582-Dec-05 4:07
User 66582-Dec-05 4:07 
GeneralRe: How to write this C code in C#? Pin
bouli2-Dec-05 4:11
bouli2-Dec-05 4:11 
AnswerRe: How to write this C code in C#? Pin
mcljava2-Dec-05 7:07
mcljava2-Dec-05 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.