D
David Burkinshaw
I'm seeing instances in one of our programs where a StreamWriter object
writes the same data twice. It only occurs when several messages hit at the
same millisecond. We time stamp our messages.
Here is a snippet of code.
public class clsLogWriter
{
private StreamWriter sw;
private FileStream fs;
private string strFSName;
public clsLogWriter()
{
string FSName = Application.StartupPath + @"\OurLog.log";
fs = new FileStream(FSName, FileMode.Append, FileAccess.Write,
FileShare.ReadWrite, 8196, true);
sw = new StreamWriter(fs);
sw.AutoFlush() = true;
}
public void writeLogs(string p_String)
{
sw.WriteLine(p_String);
// code to create TCPClient objects and send p_String
}
}
For some reason the sw.WriteLine(p_String) will write the same line twice
when there is heavy activity but the code below which writes to a TCP Client
object writes the same data once. We had originally set the buffer to 384
bytes which is longer than our longest expected line and when we increased
it to 8196 we started noticing the problem. We also didn't have AutoFlush on
and put sw.Flush() after the WriteLine. Does anyone know of any issues with
the StreamWriter where the buffer doesn't get flushed before another string
is sent to it? We've also seen long segments of spaces showing up in the
log.
Thanks in advance,
David
writes the same data twice. It only occurs when several messages hit at the
same millisecond. We time stamp our messages.
Here is a snippet of code.
public class clsLogWriter
{
private StreamWriter sw;
private FileStream fs;
private string strFSName;
public clsLogWriter()
{
string FSName = Application.StartupPath + @"\OurLog.log";
fs = new FileStream(FSName, FileMode.Append, FileAccess.Write,
FileShare.ReadWrite, 8196, true);
sw = new StreamWriter(fs);
sw.AutoFlush() = true;
}
public void writeLogs(string p_String)
{
sw.WriteLine(p_String);
// code to create TCPClient objects and send p_String
}
}
For some reason the sw.WriteLine(p_String) will write the same line twice
when there is heavy activity but the code below which writes to a TCP Client
object writes the same data once. We had originally set the buffer to 384
bytes which is longer than our longest expected line and when we increased
it to 8196 we started noticing the problem. We also didn't have AutoFlush on
and put sw.Flush() after the WriteLine. Does anyone know of any issues with
the StreamWriter where the buffer doesn't get flushed before another string
is sent to it? We've also seen long segments of spaces showing up in the
log.
Thanks in advance,
David