logger: Don't let the debug log get too big

This commit is contained in:
Hylke Bons 2012-09-23 12:58:33 +01:00
parent 9a7b5b8827
commit c3b5cbab7c

View file

@ -23,7 +23,7 @@ namespace SparkleLib {
public static class SparkleLogger {
private static Object debug_lock = new Object ();
private static int log_size = 0;
public static void LogInfo (string type, string message)
{
@ -33,8 +33,17 @@ namespace SparkleLib {
if (SparkleConfig.DebugMode)
Console.WriteLine (line);
lock (debug_lock)
File.AppendAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine);
lock (debug_lock) {
// Don't let the log get bigger than 1000 lines
if (log_size >= 1000) {
File.WriteAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine);
log_size = 0;
} else {
File.AppendAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine);
log_size++;
}
}
}