From 16bb40229b84cff5f2543591464256907855cb2a Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 20 Feb 2013 14:10:32 -0800 Subject: Add flush after write feature to LogWriter --- .../CoreModules/Framework/Statistics/Logging/LogWriter.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Framework/Statistics/Logging/LogWriter.cs b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/LogWriter.cs index fd8d5e3..3c8e0ef 100755 --- a/OpenSim/Region/CoreModules/Framework/Statistics/Logging/LogWriter.cs +++ b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/LogWriter.cs @@ -52,6 +52,7 @@ namespace OpenSim.Region.CoreModules.Framework.Statistics.Logging private TimeSpan m_logFileLife; private DateTime m_logFileEndTime; private Object m_logFileWriteLock = new Object(); + private bool m_flushWrite; // set externally when debugging. If let 'null', this does not write any error messages. public ILog ErrorLogger = null; @@ -73,7 +74,9 @@ namespace OpenSim.Region.CoreModules.Framework.Statistics.Logging /// The directory to create the log file in. May be 'null' for default. /// The characters that begin the log file name. May be 'null' for default. /// Maximum age of a log file in minutes. If zero, will set default. - public LogWriter(string dir, string headr, int maxFileTime) + /// Whether to do a flush after every log write. Best left off but + /// if one is looking for a crash, this is a good thing to turn on. + public LogWriter(string dir, string headr, int maxFileTime, bool flushWrite) { m_logDirectory = dir == null ? "." : dir; @@ -86,8 +89,14 @@ namespace OpenSim.Region.CoreModules.Framework.Statistics.Logging m_logFileLife = new TimeSpan(0, m_logMaxFileTimeMin, 0); m_logFileEndTime = DateTime.Now + m_logFileLife; + m_flushWrite = flushWrite; + Enabled = true; } + // Constructor that assumes flushWrite is off. + public LogWriter(string dir, string headr, int maxFileTime) : this(dir, headr, maxFileTime, false) + { + } public void Dispose() { @@ -153,6 +162,8 @@ namespace OpenSim.Region.CoreModules.Framework.Statistics.Logging buff.Append(line); buff.Append("\r\n"); m_logFile.Write(buff.ToString()); + if (m_flushWrite) + m_logFile.Flush(); } } } -- cgit v1.1