Updated Logger and Created Command to change settings variables

This commit is contained in:
2023-10-01 14:11:34 +03:00
parent f58a57c6cd
commit 6279c5c3a9
7 changed files with 139 additions and 5 deletions

View File

@@ -138,7 +138,13 @@ internal class CommandHandler
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
DBCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean);
Config.Logger.Log(
message: $"User ({context.User.Username}) from Guild \"{context.Guild.Name}\" executed command \"{cmd.cleanContent}\"",
source: typeof(CommandHandler),
type: LogType.INFO
);
if (context.Channel is SocketDMChannel)
plugin.ExecuteDM(cmd);
else plugin.ExecuteServer(cmd);

View File

@@ -37,7 +37,7 @@ public class Config
_isLoaded = true;
await Logger.Log(message: "Config initialized", source: typeof(Config));
Logger.Log(message: "Config initialized", source: typeof(Config));
}
}

View File

@@ -11,7 +11,7 @@ internal interface ILogger
bool OutputToFile { get; init; }
event EventHandler<Log> OnLog;
Task Log(
void Log(
string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO,
DateTime throwTime = default);
}

View File

@@ -38,7 +38,7 @@ public sealed class Logger : ILogger
(UseShortVersion ? logMessage : logMessage.AsLongString()) + "\n");
}
public async Task Log(string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO, DateTime throwTime = default)
public async void Log(string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO, DateTime throwTime = default)
{
if (!IsEnabled) return;
@@ -53,5 +53,17 @@ public sealed class Logger : ILogger
if (source == default) source = typeof(Log);
await Log(new Log(message, outputFile, source, type, throwTime));
}
public async void Log(Exception exception, LogType logType = LogType.ERROR, Type? source = null)
{
if (!IsEnabled) return;
if (logType < LowestLogLevel) return;
await Log(new Log(exception.Message,
Config.AppSettings["LogFolder"] + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log",
source, logType, DateTime.Now));
}
}