From 5e9a6bf3293a99ca56d7e5577cc19c7b18339b2c Mon Sep 17 00:00:00 2001 From: White Date: Sat, 28 Feb 2015 18:39:39 +1030 Subject: [PATCH] Switch if to while and resolve inverted for looping issue --- TShockAPI/SqlLog.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TShockAPI/SqlLog.cs b/TShockAPI/SqlLog.cs index 3655149f..bb3987c0 100644 --- a/TShockAPI/SqlLog.cs +++ b/TShockAPI/SqlLog.cs @@ -234,11 +234,11 @@ namespace TShockAPI level, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), caller, message); - if (_failures.Count > 0) + var success = true; + while (_failures.Count > 0 && success) { - var info = _failures.Last(); - var success = true; - + var info = _failures.First(); + try { _database.Query("INSERT INTO Logs (LogLevel, TimeStamp, Caller, Message) VALUES (@0, @1, @2, @3)", @@ -257,7 +257,7 @@ namespace TShockAPI } if (success) - _failures.RemoveAt(_failures.Count - 1); + _failures.RemoveAt(0); } } catch (Exception ex) @@ -278,9 +278,9 @@ namespace TShockAPI _useTextLog = true; _backupLog.ConsoleError("SQL Logging disabled due to errors. Reverting to text logging."); - for (var i = _failures.Count - 1; i >= 0; --i) + foreach(var logInfo in _failures) { - _backupLog.Write(String.Format("SQL log failed at: {0}. {1}", _failures[i].timestamp, _failures[i]), + _backupLog.Write(String.Format("SQL log failed at: {0}. {1}", logInfo.timestamp, logInfo), LogLevel.Error); } _failures.Clear();