I want to create a Log file in my application. I want to use this log file to put the text received & transmitted on my PC serial port throgh my C# application. I am receiving large text on my PC serial port. Is there is any special class to create a log file in C#.

I have some doubts for what you told me to do...can you please give some informtion on these things...

In my application if i am receiving data 10 times & i'm transmitting data 10 times then every time i have to open & close the file or no need of opening the file evrey time.

Only on the application exit i have to close the file...

Since i'll recieve & transmit large data wont it be a problem if everytime i have to open & close the file... & what if my file size becomes too large if i received very learge data which i logged in that Log file...

I have some doubts for what you told me to do...can you please give some informtion on these things...

In my application if i am receiving data 10 times & i'm transmitting data 10 times then every time i have to open & close the file or no need of opening the file evrey time.

Only on the application exit i have to close the file...

Since i'll recieve & transmit large data wont it be a problem if everytime i have to open & close the file... & what if my file size becomes too large if i received very learge data which i logged in that Log file...

Vinay

in this case, the BEST thing you can do is write it to a string then at the end of your app, write it to the file. It will also be less expensive.

One last thing...wont that StringBuilder variable "theLogEntry" will cause any problem to my running application if data to logged goes beyond say 10000 or more lines... (means if my logged data becomes too large)

Can i check file size or stringbuilder length by any chance(say 100KB)... If it is greater than this size then close first & make another file...

im not sure about that to be honest. It would probably handle itself. If you are going to be storing a large amount of strings, I would advise against it as I still think this is going to be overkill but you could use a MemoryStream and append data to that. The memorystream appends to itself and uses the memory as a backing storage. Then you can write the contents to file afterwards:

again, I would advise against it since it maybe overkill for what you are trying to do.

perhaps at regular intervals, using a timer or something, write the contents of the stringbuilder to disk (as shown previously) then clear out the stringbuilder and start over again but appending to the file, giving the second parameter "true" to append to the file.

this would be a work around to perhaps prevent any overruns or length exceeded/memory issues when appending to the stringbuilder if you are appending large amounts of strings in memory.