Merge pull request #889 from WhiteXZ/general-devel
Add FileName to ILog interface. Also fixes some missing XML warnings
This commit is contained in:
commit
518847b4e3
5 changed files with 108 additions and 136 deletions
|
|
@ -17,36 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
[Flags]
|
|
||||||
public enum LogLevel
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Debug = 1,
|
|
||||||
Info = 2,
|
|
||||||
Warning = 4,
|
|
||||||
Error = 8,
|
|
||||||
Data = 16,
|
|
||||||
All = 31
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logging interface
|
/// Logging interface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ILog
|
public interface ILog
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log name
|
/// Log file name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
string FileName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether the log level contains the specified flag.
|
/// Checks whether the log level contains the specified flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">The <see cref="LogLevel" /> value to check.</param>
|
/// <param name="type">The <see cref="LogLevel" /> value to check.</param>
|
||||||
bool MayWriteType(LogLevel type);
|
bool MayWriteType(TraceLevel type);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log and to the console.
|
/// Writes an informative string to the log and to the console.
|
||||||
|
|
@ -57,7 +46,7 @@ namespace TShockAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log and to the console.
|
/// Writes an informative string to the log and to the console.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The format of the message to be written.</param>
|
/// <param name="format">The format of the message to be written.</param>
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
void ConsoleInfo(string format, params object[] args);
|
void ConsoleInfo(string format, params object[] args);
|
||||||
|
|
||||||
|
|
@ -92,6 +81,7 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
void Error(string message);
|
void Error(string message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an error to the log.
|
/// Writes an error to the log.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -130,13 +120,13 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">Message to write</param>
|
/// <param name="message">Message to write</param>
|
||||||
/// <param name="level">LogLevel assosciated with the message</param>
|
/// <param name="level">LogLevel assosciated with the message</param>
|
||||||
void Write(string message, LogLevel level);
|
void Write(string message, TraceLevel level);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a debug string to the log file.
|
/// Writes a debug string to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
void Debug(String message);
|
void Debug(string message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a debug string to the log file.
|
/// Writes a debug string to the log file.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -27,9 +28,9 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.Data")]
|
[Obsolete("Please use TShock.Log.Data")]
|
||||||
public static void Data(String message)
|
public static void Data(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Data);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -40,7 +41,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.Data")]
|
[Obsolete("Please use TShock.Log.Data")]
|
||||||
public static void Data(string format, params object[] args)
|
public static void Data(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Data(String.Format(format, args));
|
Data(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -48,9 +49,9 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.Error")]
|
[Obsolete("Please use TShock.Log.Error")]
|
||||||
public static void Error(String message)
|
public static void Error(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -61,7 +62,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.Error")]
|
[Obsolete("Please use TShock.Log.Error")]
|
||||||
public static void Error(string format, params object[] args)
|
public static void Error(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Error(String.Format(format, args));
|
Error(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -69,12 +70,12 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.ConsoleError")]
|
[Obsolete("Please use TShock.Log.ConsoleError")]
|
||||||
public static void ConsoleError(String message)
|
public static void ConsoleError(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -85,7 +86,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.ConsoleError")]
|
[Obsolete("Please use TShock.Log.ConsoleError")]
|
||||||
public static void ConsoleError(string format, params object[] args)
|
public static void ConsoleError(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleError(String.Format(format, args));
|
ConsoleError(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -93,9 +94,9 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.Warn")]
|
[Obsolete("Please use TShock.Log.Warn")]
|
||||||
public static void Warn(String message)
|
public static void Warn(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Warning);
|
Write(message, TraceLevel.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -106,7 +107,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.Warn")]
|
[Obsolete("Please use TShock.Log.Warn")]
|
||||||
public static void Warn(string format, params object[] args)
|
public static void Warn(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Warn(String.Format(format, args));
|
Warn(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -114,9 +115,9 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.Info")]
|
[Obsolete("Please use TShock.Log.Info")]
|
||||||
public static void Info(String message)
|
public static void Info(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -127,7 +128,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.Info")]
|
[Obsolete("Please use TShock.Log.Info")]
|
||||||
public static void Info(string format, params object[] args)
|
public static void Info(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Info(String.Format(format, args));
|
Info(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -135,12 +136,12 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.ConsoleInfo")]
|
[Obsolete("Please use TShock.Log.ConsoleInfo")]
|
||||||
public static void ConsoleInfo(String message)
|
public static void ConsoleInfo(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -151,7 +152,7 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.ConsoleInfo")]
|
[Obsolete("Please use TShock.Log.ConsoleInfo")]
|
||||||
public static void ConsoleInfo(string format, params object[] args)
|
public static void ConsoleInfo(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleInfo(String.Format(format, args));
|
ConsoleInfo(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -159,9 +160,9 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
[Obsolete("Please use TShock.Log.Debug")]
|
[Obsolete("Please use TShock.Log.Debug")]
|
||||||
public static void Debug(String message)
|
public static void Debug(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Debug);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -172,13 +173,13 @@ namespace TShockAPI
|
||||||
[Obsolete("Please use TShock.Log.Debug")]
|
[Obsolete("Please use TShock.Log.Debug")]
|
||||||
public static void Debug(string format, params object[] args)
|
public static void Debug(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Debug(String.Format(format, args));
|
Debug(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal method which writes a message directly to the log file.
|
/// Internal method which writes a message directly to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void Write(String message, LogLevel level)
|
private static void Write(string message, TraceLevel level)
|
||||||
{
|
{
|
||||||
TShock.Log.Write(message, level);
|
TShock.Log.Write(message, level);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ namespace TShockAPI
|
||||||
public string timestamp;
|
public string timestamp;
|
||||||
public string message;
|
public string message;
|
||||||
public string caller;
|
public string caller;
|
||||||
public LogLevel logLevel;
|
public TraceLevel logLevel;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("Message: {0}: {1}: {2}",
|
return string.Format("Message: {0}: {1}: {2}",
|
||||||
caller, logLevel.ToString().ToUpper(), message);
|
caller, logLevel.ToString().ToUpper(), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,36 +45,38 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SqlLog : ILog, IDisposable
|
public class SqlLog : ILog, IDisposable
|
||||||
{
|
{
|
||||||
private readonly LogLevel _logLevel;
|
|
||||||
private readonly IDbConnection _database;
|
private readonly IDbConnection _database;
|
||||||
private readonly TextLog _backupLog;
|
private readonly TextLog _backupLog;
|
||||||
private readonly List<LogInfo> _failures = new List<LogInfo>(TShock.Config.RevertToTextLogsOnSqlFailures);
|
private readonly List<LogInfo> _failures = new List<LogInfo>(TShock.Config.RevertToTextLogsOnSqlFailures);
|
||||||
private bool _useTextLog;
|
private bool _useTextLog;
|
||||||
|
|
||||||
public string Name
|
public string FileName { get; set; }
|
||||||
{
|
|
||||||
get { return "SQL Log Writer"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlLog(LogLevel logLevel, IDbConnection db, string textlogFilepath, bool clearTextLog)
|
/// <summary>
|
||||||
|
/// Sets the database connection and the initial log level.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
|
/// <param name="textlogFilepath">File path to a backup text log in case the SQL log fails</param>
|
||||||
|
/// <param name="clearTextLog"></param>
|
||||||
|
public SqlLog(IDbConnection db, string textlogFilepath, bool clearTextLog)
|
||||||
{
|
{
|
||||||
_logLevel = logLevel;
|
FileName = string.Format("{0}://database", db.GetSqlType());
|
||||||
_database = db;
|
_database = db;
|
||||||
_backupLog = new TextLog(textlogFilepath, logLevel, clearTextLog);
|
_backupLog = new TextLog(textlogFilepath, clearTextLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MayWriteType(LogLevel type)
|
public bool MayWriteType(TraceLevel type)
|
||||||
{
|
{
|
||||||
return ((_logLevel & type) == type);
|
return type != TraceLevel.Off;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes data to the log file.
|
/// Writes data to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Data(String message)
|
public void Data(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Data);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -84,16 +86,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Data(string format, params object[] args)
|
public void Data(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Data(String.Format(format, args));
|
Data(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an error to the log file.
|
/// Writes an error to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Error(String message)
|
public void Error(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -103,19 +105,19 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Error(string format, params object[] args)
|
public void Error(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Error(String.Format(format, args));
|
Error(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an error to the log file.
|
/// Writes an error to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void ConsoleError(String message)
|
public void ConsoleError(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -125,16 +127,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void ConsoleError(string format, params object[] args)
|
public void ConsoleError(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleError(String.Format(format, args));
|
ConsoleError(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a warning to the log file.
|
/// Writes a warning to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Warn(String message)
|
public void Warn(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Warning);
|
Write(message, TraceLevel.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -144,16 +146,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Warn(string format, params object[] args)
|
public void Warn(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Warn(String.Format(format, args));
|
Warn(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log file.
|
/// Writes an informative string to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Info(String message)
|
public void Info(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -163,19 +165,19 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Info(string format, params object[] args)
|
public void Info(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Info(String.Format(format, args));
|
Info(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log file. Also outputs to the console.
|
/// Writes an informative string to the log file. Also outputs to the console.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void ConsoleInfo(String message)
|
public void ConsoleInfo(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -185,16 +187,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void ConsoleInfo(string format, params object[] args)
|
public void ConsoleInfo(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleInfo(String.Format(format, args));
|
ConsoleInfo(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a debug string to the log file.
|
/// Writes a debug string to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Debug(String message)
|
public void Debug(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Debug);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -204,10 +206,10 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Debug(string format, params object[] args)
|
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)
|
public void Write(string message, TraceLevel level)
|
||||||
{
|
{
|
||||||
if (!MayWriteType(level))
|
if (!MayWriteType(level))
|
||||||
return;
|
return;
|
||||||
|
|
@ -250,8 +252,8 @@ namespace TShockAPI
|
||||||
_failures.Add(new LogInfo
|
_failures.Add(new LogInfo
|
||||||
{
|
{
|
||||||
caller = "TShock",
|
caller = "TShock",
|
||||||
logLevel = LogLevel.Error,
|
logLevel = TraceLevel.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)
|
timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -280,8 +282,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
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);
|
TraceLevel.Error);
|
||||||
}
|
}
|
||||||
_failures.Clear();
|
_failures.Clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,15 +202,10 @@ namespace TShockAPI
|
||||||
throw new Exception("Invalid storage type");
|
throw new Exception("Invalid storage type");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
var level = LogLevel.All;
|
|
||||||
#else
|
|
||||||
var level = LogLevel.All & ~LogLevel.Debug;
|
|
||||||
#endif
|
|
||||||
if (Config.UseSqlLogs)
|
if (Config.UseSqlLogs)
|
||||||
Log = new SqlLog(level, DB, logFilename, LogClear);
|
Log = new SqlLog(DB, logFilename, LogClear);
|
||||||
else
|
else
|
||||||
Log = new TextLog(logFilename, level, LogClear);
|
Log = new TextLog(logFilename, LogClear);
|
||||||
|
|
||||||
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,51 +30,35 @@ namespace TShockAPI
|
||||||
public class TextLog : ILog, IDisposable
|
public class TextLog : ILog, IDisposable
|
||||||
{
|
{
|
||||||
private readonly StreamWriter _logWriter;
|
private readonly StreamWriter _logWriter;
|
||||||
private readonly LogLevel _logLevel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log file name
|
/// File name of the Text log
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string fileName { get; private set; }
|
public string FileName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Name of the TextLog
|
|
||||||
/// </summary>
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get { return "Text Log Writer"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Sql
|
|
||||||
{
|
|
||||||
get { return false; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the log file stream and sets the initial log level.
|
/// Creates the log file stream and sets the initial log level.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The output filename. This file will be overwritten if 'clear' is set.</param>
|
/// <param name="filename">The output filename. This file will be overwritten if 'clear' is set.</param>
|
||||||
/// <param name="logLevel">The <see cref="LogLevel" /> value which sets the type of messages to output.</param>
|
|
||||||
/// <param name="clear">Whether or not to clear the log file on initialization.</param>
|
/// <param name="clear">Whether or not to clear the log file on initialization.</param>
|
||||||
public TextLog(string filename, LogLevel logLevel, bool clear)
|
public TextLog(string filename, bool clear)
|
||||||
{
|
{
|
||||||
fileName = filename;
|
FileName = filename;
|
||||||
_logLevel = logLevel;
|
|
||||||
_logWriter = new StreamWriter(filename, !clear);
|
_logWriter = new StreamWriter(filename, !clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MayWriteType(LogLevel type)
|
public bool MayWriteType(TraceLevel type)
|
||||||
{
|
{
|
||||||
return ((_logLevel & type) == type);
|
return type != TraceLevel.Off;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes data to the log file.
|
/// Writes data to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Data(String message)
|
public void Data(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Data);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -84,16 +68,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Data(string format, params object[] args)
|
public void Data(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Data(String.Format(format, args));
|
Data(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an error to the log file.
|
/// Writes an error to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Error(String message)
|
public void Error(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -103,19 +87,19 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Error(string format, params object[] args)
|
public void Error(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Error(String.Format(format, args));
|
Error(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an error to the log file.
|
/// Writes an error to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void ConsoleError(String message)
|
public void ConsoleError(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Error);
|
Write(message, TraceLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -125,16 +109,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void ConsoleError(string format, params object[] args)
|
public void ConsoleError(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleError(String.Format(format, args));
|
ConsoleError(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a warning to the log file.
|
/// Writes a warning to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Warn(String message)
|
public void Warn(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Warning);
|
Write(message, TraceLevel.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -144,16 +128,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Warn(string format, params object[] args)
|
public void Warn(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Warn(String.Format(format, args));
|
Warn(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log file.
|
/// Writes an informative string to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Info(String message)
|
public void Info(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -163,19 +147,19 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Info(string format, params object[] args)
|
public void Info(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Info(String.Format(format, args));
|
Info(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an informative string to the log file. Also outputs to the console.
|
/// Writes an informative string to the log file. Also outputs to the console.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void ConsoleInfo(String message)
|
public void ConsoleInfo(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Write(message, LogLevel.Info);
|
Write(message, TraceLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -185,16 +169,16 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void ConsoleInfo(string format, params object[] args)
|
public void ConsoleInfo(string format, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleInfo(String.Format(format, args));
|
ConsoleInfo(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a debug string to the log file.
|
/// Writes a debug string to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to be written.</param>
|
/// <param name="message">The message to be written.</param>
|
||||||
public void Debug(String message)
|
public void Debug(string message)
|
||||||
{
|
{
|
||||||
Write(message, LogLevel.Debug);
|
Write(message, TraceLevel.Verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -204,7 +188,7 @@ namespace TShockAPI
|
||||||
/// <param name="args">The format arguments.</param>
|
/// <param name="args">The format arguments.</param>
|
||||||
public void Debug(string format, params object[] args)
|
public void Debug(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Debug(String.Format(format, args));
|
Debug(string.Format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -212,7 +196,7 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <param name="level"></param>
|
/// <param name="level"></param>
|
||||||
public void Write(string message, LogLevel level)
|
public void Write(string message, TraceLevel level)
|
||||||
{
|
{
|
||||||
if (!MayWriteType(level))
|
if (!MayWriteType(level))
|
||||||
return;
|
return;
|
||||||
|
|
@ -227,7 +211,7 @@ namespace TShockAPI
|
||||||
caller = meth.DeclaringType.Name;
|
caller = meth.DeclaringType.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var logEntry = String.Format("{0} - {1}: {2}: {3}",
|
var logEntry = string.Format("{0} - {1}: {2}: {3}",
|
||||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||||
caller, level.ToString().ToUpper(), message);
|
caller, level.ToString().ToUpper(), message);
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue