99390f1f35
view angle vector parse fail is now a handled exception change local host check to byte array to make it faster than comparing string kick command now requires moderator level or higher tempban now requires administrator level or higher hopefully fixed negative SPM bug pipelined the events and consolidated them to run through GameEventHandler uniform console colors
85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
using SharedLibraryCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace IW4MAdmin.Application
|
|
{
|
|
class Logger : SharedLibraryCore.Interfaces.ILogger
|
|
{
|
|
enum LogType
|
|
{
|
|
Verbose,
|
|
Info,
|
|
Debug,
|
|
Warning,
|
|
Error,
|
|
Assert
|
|
}
|
|
|
|
string FileName;
|
|
object ThreadLock;
|
|
|
|
public Logger(string fn)
|
|
{
|
|
FileName = fn;
|
|
ThreadLock = new object();
|
|
if (File.Exists(fn))
|
|
File.Delete(fn);
|
|
}
|
|
|
|
void Write(string msg, LogType type)
|
|
{
|
|
if (!Utilities.CurrentLocalization.LocalizationSet.TryGetValue($"GLOBAL_{type.ToString().ToUpper()}", out string stringType))
|
|
stringType = type.ToString();
|
|
|
|
string LogLine = $"[{DateTime.Now.ToString("HH:mm:ss")}] - {stringType}: {msg}";
|
|
lock (ThreadLock)
|
|
{
|
|
#if DEBUG
|
|
// lets keep it simple and dispose of everything quickly as logging wont be that much (relatively)
|
|
|
|
Console.WriteLine(LogLine);
|
|
File.AppendAllText(FileName, LogLine + Environment.NewLine);
|
|
#else
|
|
if (type == LogType.Error || type == LogType.Verbose)
|
|
Console.WriteLine(LogLine);
|
|
//if (type != LogType.Debug)
|
|
File.AppendAllText(FileName, $"{LogLine}{Environment.NewLine}");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public void WriteVerbose(string msg)
|
|
{
|
|
Write(msg, LogType.Verbose);
|
|
}
|
|
|
|
public void WriteDebug(string msg)
|
|
{
|
|
Write(msg, LogType.Debug);
|
|
}
|
|
|
|
public void WriteError(string msg)
|
|
{
|
|
Write(msg, LogType.Error);
|
|
}
|
|
|
|
public void WriteInfo(string msg)
|
|
{
|
|
Write(msg, LogType.Info);
|
|
}
|
|
|
|
public void WriteWarning(string msg)
|
|
{
|
|
Write(msg, LogType.Warning);
|
|
}
|
|
|
|
public void WriteAssert(bool condition, string msg)
|
|
{
|
|
if (!condition)
|
|
Write(msg, LogType.Assert);
|
|
}
|
|
}
|
|
}
|