473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

StreamWriter is not reliable

6
for who have any idea about my question.

I have a multithread middle tier engine and use StreamWriter to log events to console and files. I run the engine for whole night (6 - 10 hours) and there are 8 batch log files generated. Sometimes some log files (one or two of 8) is cut off on the very last portion. I thought it might be because buffer is not flushed out. But I use AutoFlush and Flush. The problem still exist. Do some body have the same problem with StreamWriter? The problem is I cannot re-produce the problem when on debug mode and runnning in my local machine. It seems always happening when the app compiled and deployed to a server machine.
Feb 5 '08 #1
7 1713
jhaxo
57
I have never had an issue with StreamWriter itself, I think you should take a higher-level look to see if you have an application problem. dead lock, or file access or plain-old-fashion running out of disk space.
Feb 5 '08 #2
yfguo
6
Thank your reply.

But I have no space problem. The space still has 10 GB. No security, permission problem, because it has already been written several hundreds bytes log. I used to guess it is a problem of dead lock, because I use multithreading. However I already took care of the thread safe issue. Because of the complication of the multithread logging, so it is still the candidate. Another candidate is buffer flushing problem.

Any other thoughts?
Feb 5 '08 #3
Shashi Sadasivan
1,435 Expert 1GB
Is each thread writing a seperate log file?
or can more than one thread edit/create the same log file?

If more than 2 threads can write to the same log file, what you are experiencing is the need to centralize writing to a file.

Its similar to have a document open in one window, and then trying to edit the same document in another one.

Try using a static/singleton class to handle writing of events to the logs.
Feb 6 '08 #4
yfguo
6
it is writing to one log file for multithreads and I am using a static WriteLogEntry method.

Today I created a dummy project to see if it is the problem of multithreading. But it looks I can run 1000 threads without any problem (message lost) to WriteLogEntry to one log file.

Actually there is only one batch log file of the 7 batch log files missing the log message from middle somewhere from where there are no any logs. All these 8 batch jobs run in sequent (not parallel) for over 6 hours.
Feb 6 '08 #5
Shashi Sadasivan
1,435 Expert 1GB
Is there a possibility that you could provide us with that sample project you made, so that we can have more information what is going wrong.

Also please insert appropriate comments in the code if you decide to provide it
Feb 6 '08 #6
Are you doing a Close() on the StreamWriter object you are using.

Go to visual Studio->Debug->Exceptions->Managed Debugging Assists and enable StreamWriterBufferedDataLost

This would raise an exception in case an S W object is not closed before finalize().

Read this article ..
http://blogs.msdn.com/bclteam/archiv...13/214405.aspx

90% of the times its Close() that gives problems, atleast for me. I use StreamWriter to log 1000's of URL for my research and usually i do not lose any data.
Feb 7 '08 #7
yfguo
6
I think the problem has been resovled. The problem I guess is because I did not close the StreamWriter. When I add code to close the streaWirter, the problem goes away.

Thanks for all you guys' comments and help.
Feb 12 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vladimir Bezugliy | last post by:
I have a server that listen a socket. And I have next client: TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000); NetworkStream networkStream = socketForServer.GetStream();...
4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
1
by: Daniel | last post by:
i would like to konw when the data sent so that i can close the streamwriter and networkstream is there some sort of call backs/events i have to implement for this to work? if so how? can i just...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
4
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it....
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
1
by: Max Powers | last post by:
Hello, I have a VB.NET code that creates a StreamWriter file first and then it does a series of procedures that write lines for this StreamWriter. When all the procedures are done, the...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
3
by: stumorgan | last post by:
I'm doing some USB communications in C# and am running into a minor annoyance. I'm using the Windows API CreateFile function to get a SafeFileHandle, which I then stuff into a FileStream and from...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.