StackOverFlowExceprion raised
, when logDirectory = new DirectoryInfo(m_logFileDirectory);
line was executing. How can I solve the problem? Please help me.
This procedure writeLogToFile
write a logMessge
to File
to logDirectory
.
It is part of Log
write program.
private void writeLogToFile(string logMessge)
{
DirectoryInfo logDirectory = null;
try
{
Monitor.Enter(m_lock);
logDirectory = new DirectoryInfo(m_logFileDirectory);
if (!logDirectory.Exists)
{
logDirectory.Create();
}
if (m_streamWriter == null) newLogFile();
if (m_logFileAutoSeperate && (m_streamWriter.BaseStream.Length > m_logFileSize * 1024))
{
newLogFile();
m_streamWriter.WriteLine(logMessge);
}
else
{
m_streamWriter.WriteLine(logMessge);
}
// stream writer uses internal buffer.
// if directWriting option is true, the file will be write(flush) once.
if (directWriting) m_streamWriter.Flush();
}
catch (StackOverflowException sofex)
{
AppExceptionHandler.writeException(sofex);
}
catch (AppException aex)
{
AppExceptionHandler.writeException(aex);
}
catch (Exception ex)
{
AppExceptionHandler.writeException(ex);
}
finally
{
Monitor.Exit(m_lock);
}
}
From the comments, this is what newLogFile
looks like:
private void newLogFile()
{
try
{
Monitor.Enter(m_lock);
if (m_streamWriter != null)
{
endLogging();
m_streamWriter.Flush();
m_streamWriter.Close();
}
m_logFileNameSuffix = getLogFileNewSuffix();
m_streamWriter = File.AppendText(getLogFileName());
startLogging();
}
}