mirror of https://github.com/winsw/winsw
fixed a bug in the log rotation
git-svn-id: https://svn.kenai.com/svn/winsw~subversion/trunk@40 c8b2a3fe-9b5b-6a51-a37e-dc31b0e308faremotes/git-svn
parent
21c156f2c8
commit
fb063c16d4
22
Main.cs
22
Main.cs
|
@ -225,7 +225,7 @@ namespace winsw
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logmode to 'reset', 'roll' once or 'append' [default] the out.log and err.log files.
|
/// Logmode to 'reset', 'rotate' once or 'append' [default] the out.log and err.log files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Logmode
|
public string Logmode
|
||||||
{
|
{
|
||||||
|
@ -464,9 +464,9 @@ namespace winsw
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy stuff from StreamReader to StreamWriter
|
/// Copy stuff from StreamReader to StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CopyStream(StreamReader i, StreamWriter o)
|
private void CopyStream(Stream i, Stream o)
|
||||||
{
|
{
|
||||||
char[] buf = new char[1024];
|
byte[] buf = new byte[1024];
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int sz = i.Read(buf, 0, buf.Length);
|
int sz = i.Read(buf, 0, buf.Length);
|
||||||
|
@ -492,10 +492,11 @@ namespace winsw
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int len = data.Read(buf, 0, buf.Length);
|
int len = data.Read(buf, 0, buf.Length);
|
||||||
if (len == 0) break;
|
if (len == 0) break; // EOF
|
||||||
if (sz + len < THRESHOLD)
|
if (sz + len < THRESHOLD)
|
||||||
{// typical case. write the whole thing into the current file
|
{// typical case. write the whole thing into the current file
|
||||||
w.Write(buf, 0, len);
|
w.Write(buf, 0, len);
|
||||||
|
sz += len;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -520,7 +521,8 @@ namespace winsw
|
||||||
string src = baseName + "." + (j + 0) + ext;
|
string src = baseName + "." + (j + 0) + ext;
|
||||||
if (File.Exists(dst))
|
if (File.Exists(dst))
|
||||||
File.Delete(dst);
|
File.Delete(dst);
|
||||||
File.Move(src, dst);
|
if (File.Exists(src))
|
||||||
|
File.Move(src, dst);
|
||||||
}
|
}
|
||||||
File.Move(baseName + ext, baseName + ".0" + ext);
|
File.Move(baseName + ext, baseName + ".0" + ext);
|
||||||
}
|
}
|
||||||
|
@ -529,10 +531,14 @@ namespace winsw
|
||||||
LogEvent("Failed to rotate log: " + e.Message);
|
LogEvent("Failed to rotate log: " + e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
w = new FileStream(baseName + ext, FileMode.Append);
|
// even if the log rotation fails, create a new one, or else
|
||||||
|
// we'll infinitely try to rotate.
|
||||||
|
w = new FileStream(baseName + ext, FileMode.Create);
|
||||||
sz = new FileInfo(baseName + ext).Length;
|
sz = new FileInfo(baseName + ext).Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Flush();
|
||||||
}
|
}
|
||||||
data.Close();
|
data.Close();
|
||||||
w.Close();
|
w.Close();
|
||||||
|
@ -623,8 +629,8 @@ namespace winsw
|
||||||
CopyFile(errorLogfilename, errorLogfilename + ".old");
|
CopyFile(errorLogfilename, errorLogfilename + ".old");
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(delegate() { CopyStream(process.StandardOutput, new StreamWriter(new FileStream(outputLogfilename, fileMode))); }).Start();
|
new Thread(delegate() { CopyStream(process.StandardOutput.BaseStream, new FileStream(outputLogfilename, fileMode)); }).Start();
|
||||||
new Thread(delegate() { CopyStream(process.StandardError, new StreamWriter(new FileStream(errorLogfilename, fileMode))); }).Start();
|
new Thread(delegate() { CopyStream(process.StandardError.BaseStream, new FileStream(errorLogfilename, fileMode)); }).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogEvent(String message)
|
private void LogEvent(String message)
|
||||||
|
|
Loading…
Reference in New Issue