diff --git a/TShockAPI/ILog.cs b/TShockAPI/ILog.cs
index a8c65eaf..2b1c0f66 100644
--- a/TShockAPI/ILog.cs
+++ b/TShockAPI/ILog.cs
@@ -20,27 +20,57 @@ using System;
namespace TShockAPI
{
+ ///
+ /// Flags to define which types of message are logged
+ ///
[Flags]
public enum LogLevel
{
+ ///
+ /// No messages will be logged
+ ///
None = 0,
+
+ ///
+ /// Debug messages will be logged
+ ///
Debug = 1,
+
+ ///
+ /// Informative messages will be logged
+ ///
Info = 2,
+
+ ///
+ /// Warning message will be logged
+ ///
Warning = 4,
+
+ ///
+ /// Error messages will be logged
+ ///
Error = 8,
+
+ ///
+ /// Data messages will be logged
+ ///
Data = 16,
+
+ ///
+ /// All messages will be logged
+ ///
All = 31
}
-///
-/// Logging interface
-///
+ ///
+ /// Logging interface
+ ///
public interface ILog
{
///
- /// Log name
+ /// Log file name
///
- string Name { get; }
+ string FileName { get; set; }
///
/// Checks whether the log level contains the specified flag.
@@ -57,7 +87,7 @@ namespace TShockAPI
///
/// Writes an informative string to the log and to the console.
///
- /// The format of the message to be written.
+ /// The format of the message to be written.
/// The format arguments.
void ConsoleInfo(string format, params object[] args);
@@ -92,6 +122,7 @@ namespace TShockAPI
///
/// The message to be written.
void Error(string message);
+
///
/// Writes an error to the log.
///
@@ -150,4 +181,4 @@ namespace TShockAPI
///
void Dispose();
}
-}
+}
\ No newline at end of file
diff --git a/TShockAPI/SqlLog.cs b/TShockAPI/SqlLog.cs
index bb3987c0..763eca8a 100644
--- a/TShockAPI/SqlLog.cs
+++ b/TShockAPI/SqlLog.cs
@@ -35,7 +35,7 @@ namespace TShockAPI
public override string ToString()
{
- return String.Format("Message: {0}: {1}: {2}",
+ return string.Format("Message: {0}: {1}: {2}",
caller, logLevel.ToString().ToUpper(), message);
}
}
@@ -51,13 +51,18 @@ namespace TShockAPI
private readonly List _failures = new List(TShock.Config.RevertToTextLogsOnSqlFailures);
private bool _useTextLog;
- public string Name
- {
- get { return "SQL Log Writer"; }
- }
+ public string FileName { get; set; }
+ ///
+ /// Sets the database connection and the initial log level.
+ ///
+ ///
+ ///
+ /// File path to a backup text log in case the SQL log fails
+ ///
public SqlLog(LogLevel logLevel, IDbConnection db, string textlogFilepath, bool clearTextLog)
{
+ FileName = string.Format("{0}://database", db.GetSqlType());
_logLevel = logLevel;
_database = db;
_backupLog = new TextLog(textlogFilepath, logLevel, clearTextLog);
@@ -72,7 +77,7 @@ namespace TShockAPI
/// Writes data to the log file.
///
/// The message to be written.
- public void Data(String message)
+ public void Data(string message)
{
Write(message, LogLevel.Data);
}
@@ -84,14 +89,14 @@ namespace TShockAPI
/// The format arguments.
public void Data(string format, params object[] args)
{
- Data(String.Format(format, args));
+ Data(string.Format(format, args));
}
///
/// Writes an error to the log file.
///
/// The message to be written.
- public void Error(String message)
+ public void Error(string message)
{
Write(message, LogLevel.Error);
}
@@ -103,14 +108,14 @@ namespace TShockAPI
/// The format arguments.
public void Error(string format, params object[] args)
{
- Error(String.Format(format, args));
+ Error(string.Format(format, args));
}
///
/// Writes an error to the log file.
///
/// The message to be written.
- public void ConsoleError(String message)
+ public void ConsoleError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
@@ -125,14 +130,14 @@ namespace TShockAPI
/// The format arguments.
public void ConsoleError(string format, params object[] args)
{
- ConsoleError(String.Format(format, args));
+ ConsoleError(string.Format(format, args));
}
///
/// Writes a warning to the log file.
///
/// The message to be written.
- public void Warn(String message)
+ public void Warn(string message)
{
Write(message, LogLevel.Warning);
}
@@ -144,14 +149,14 @@ namespace TShockAPI
/// The format arguments.
public void Warn(string format, params object[] args)
{
- Warn(String.Format(format, args));
+ Warn(string.Format(format, args));
}
///
/// Writes an informative string to the log file.
///
/// The message to be written.
- public void Info(String message)
+ public void Info(string message)
{
Write(message, LogLevel.Info);
}
@@ -163,14 +168,14 @@ namespace TShockAPI
/// The format arguments.
public void Info(string format, params object[] args)
{
- Info(String.Format(format, args));
+ Info(string.Format(format, args));
}
///
/// Writes an informative string to the log file. Also outputs to the console.
///
/// The message to be written.
- public void ConsoleInfo(String message)
+ public void ConsoleInfo(string message)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(message);
@@ -185,14 +190,14 @@ namespace TShockAPI
/// The format arguments.
public void ConsoleInfo(string format, params object[] args)
{
- ConsoleInfo(String.Format(format, args));
+ ConsoleInfo(string.Format(format, args));
}
///
/// Writes a debug string to the log file.
///
/// The message to be written.
- public void Debug(String message)
+ public void Debug(string message)
{
Write(message, LogLevel.Debug);
}
@@ -204,7 +209,7 @@ namespace TShockAPI
/// The format arguments.
public void Debug(string format, params object[] args)
{
- Debug(String.Format(format, args));
+ Debug(string.Format(format, args));
}
public void Write(string message, LogLevel level)
@@ -238,7 +243,7 @@ namespace TShockAPI
while (_failures.Count > 0 && success)
{
var info = _failures.First();
-
+
try
{
_database.Query("INSERT INTO Logs (LogLevel, TimeStamp, Caller, Message) VALUES (@0, @1, @2, @3)",
@@ -251,7 +256,7 @@ namespace TShockAPI
{
caller = "TShock",
logLevel = LogLevel.Error,
- message = String.Format("SQL Log insert query failed: {0}", ex),
+ message = string.Format("SQL Log insert query failed: {0}", ex),
timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
});
}
@@ -278,9 +283,9 @@ namespace TShockAPI
_useTextLog = true;
_backupLog.ConsoleError("SQL Logging disabled due to errors. Reverting to text logging.");
- foreach(var logInfo in _failures)
+ foreach (var logInfo in _failures)
{
- _backupLog.Write(String.Format("SQL log failed at: {0}. {1}", logInfo.timestamp, logInfo),
+ _backupLog.Write(string.Format("SQL log failed at: {0}. {1}", logInfo.timestamp, logInfo),
LogLevel.Error);
}
_failures.Clear();
diff --git a/TShockAPI/TextLog.cs b/TShockAPI/TextLog.cs
index 9812e168..1b662ec8 100644
--- a/TShockAPI/TextLog.cs
+++ b/TShockAPI/TextLog.cs
@@ -33,22 +33,9 @@ namespace TShockAPI
private readonly LogLevel _logLevel;
///
- /// Log file name
+ /// File name of the Text log
///
- public static string fileName { get; private set; }
-
- ///
- /// Name of the TextLog
- ///
- public string Name
- {
- get { return "Text Log Writer"; }
- }
-
- public bool Sql
- {
- get { return false; }
- }
+ public string FileName { get; set; }
///
/// Creates the log file stream and sets the initial log level.
@@ -58,7 +45,7 @@ namespace TShockAPI
/// Whether or not to clear the log file on initialization.
public TextLog(string filename, LogLevel logLevel, bool clear)
{
- fileName = filename;
+ FileName = filename;
_logLevel = logLevel;
_logWriter = new StreamWriter(filename, !clear);
}