From 9b3447e403235be6475d9b4ca27437a778d030a4 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Sat, 22 Apr 2017 12:09:47 +0200 Subject: [PATCH] Use Serilog for logging to file --- README.md | 9 ++++++--- src/iTool.DiscordBot/Logger.cs | 14 ++++++++------ src/iTool.DiscordBot/Modules/AudioModule.cs | 2 +- src/iTool.DiscordBot/Modules/TagModule.cs | 2 +- src/iTool.DiscordBot/Program.cs | 4 +--- src/iTool.DiscordBot/iTool.DiscordBot.csproj | 3 +-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 26842db..e0e54c2 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Just a Discord bot | invite | | | Returns the OAuth2 Invite URL of the bot | | leave | | GuildPermission.ManageGuild | Instructs the bot to leave this Guild | | say | echo | | Echos the provided input | -| setgame | | **Trusted user** | Sets the bot's game | +| setgame | | **Trusted user** | Sets the bots game | +| ping | | | Gets the estimated round-trip latency, in milliseconds, to the gateway server | | userinfo | | | Returns info about the user | ## Administration commands @@ -30,7 +31,7 @@ Just a Discord bot | Command | Aliases | Permission | Description | | ------- | ------- | ---------- | ----------- | | join | | | Joins the voice channel | -| stop | | | Stops the audio blayback and leaves the voice channel | +| stop | | | Stops the audio playback and leaves the voice channel | | play | | | Plays an audio files | ## Core commands @@ -74,8 +75,10 @@ Just a Discord bot | Command | Aliases | Permission | Description | | ------- | ------- | ---------- | ----------- | -| createtag | | GuildPermission.ManageMessages | Creates a new tag | +| tag create| createtag | GuildPermission.ManageMessages | Creates a new tag | | tag | | | Searches for a tag | +| tag delete | tag remove, deletetag, removetag | | Deletes a tag | +| tag list | tags list, listtags | | Lists all tags | ## Weather commands diff --git a/src/iTool.DiscordBot/Logger.cs b/src/iTool.DiscordBot/Logger.cs index f3f3e9c..020f407 100644 --- a/src/iTool.DiscordBot/Logger.cs +++ b/src/iTool.DiscordBot/Logger.cs @@ -1,5 +1,5 @@ using Discord; -using Microsoft.Extensions.Logging; +using Serilog; using System; using System.IO; using System.Threading.Tasks; @@ -8,9 +8,9 @@ namespace iTool.DiscordBot { public static class Logger { - static ILogger logger = new LoggerFactory() - .AddFile(Common.LogsDir + Path.DirectorySeparatorChar + "log-{Date}.log") - .CreateLogger(string.Empty); + static ILogger logger = new LoggerConfiguration() + .WriteTo.RollingFile(Common.LogsDir + Path.DirectorySeparatorChar + "log-{Date}.log") + .CreateLogger(); public static LogSeverity LogLevel { get; internal set; } = LogSeverity.Verbose; public static Task Log(LogMessage msg) @@ -22,17 +22,19 @@ public static Task Log(LogMessage msg) { case LogSeverity.Critical: case LogSeverity.Error: - logger.LogError($"{msg.Source}: {msg.Message}"); + logger.Error($"{msg.Source}: {msg.Message}"); Console.ForegroundColor = ConsoleColor.Red; break; case LogSeverity.Warning: + logger.Warning($"{msg.Source}: {msg.Message}"); Console.ForegroundColor = ConsoleColor.Yellow; break; case LogSeverity.Info: - logger.LogInformation($"{msg.Source}: {msg.Message}"); + logger.Information($"{msg.Source}: {msg.Message}"); break; case LogSeverity.Verbose: case LogSeverity.Debug: + logger.Debug($"{msg.Source}: {msg.Message}"); Console.ForegroundColor = ConsoleColor.DarkGray; break; } diff --git a/src/iTool.DiscordBot/Modules/AudioModule.cs b/src/iTool.DiscordBot/Modules/AudioModule.cs index 1e4bfae..53d3840 100644 --- a/src/iTool.DiscordBot/Modules/AudioModule.cs +++ b/src/iTool.DiscordBot/Modules/AudioModule.cs @@ -18,7 +18,7 @@ public async Task Join() => await AudioService.JoinAudio(Context.Guild, (Context.User as IGuildUser).VoiceChannel); [Command("stop", RunMode = RunMode.Async)] - [Summary("Stops the audio blayback and leaves the voice channel")] + [Summary("Stops the audio playback and leaves the voice channel")] [RequireContext(ContextType.Guild)] public async Task Stop() => await AudioService.LeaveAudio(Context.Guild); diff --git a/src/iTool.DiscordBot/Modules/TagModule.cs b/src/iTool.DiscordBot/Modules/TagModule.cs index b53ca33..4cfe832 100644 --- a/src/iTool.DiscordBot/Modules/TagModule.cs +++ b/src/iTool.DiscordBot/Modules/TagModule.cs @@ -88,7 +88,7 @@ public async Task TagDelete(string name) { LiteCollection col = db.GetCollection("tags"); int? id = col.Find(x => x.Title == name - && x.Author == Context.User.Id) + && (x.Author == Context.User.Id || Context.User.Id == Context.Guild.OwnerId)) .FirstOrDefault()?.Id; if (id == null) diff --git a/src/iTool.DiscordBot/Program.cs b/src/iTool.DiscordBot/Program.cs index 6c09af0..eabc91b 100644 --- a/src/iTool.DiscordBot/Program.cs +++ b/src/iTool.DiscordBot/Program.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging; -using System; +using System; using System.Threading; namespace iTool.DiscordBot @@ -7,7 +6,6 @@ namespace iTool.DiscordBot public static class Program { static bool running = true; - public static ILoggerFactory LoggerFactory; public static void Main(string[] args) { diff --git a/src/iTool.DiscordBot/iTool.DiscordBot.csproj b/src/iTool.DiscordBot/iTool.DiscordBot.csproj index 3932bcb..cdfbbd1 100644 --- a/src/iTool.DiscordBot/iTool.DiscordBot.csproj +++ b/src/iTool.DiscordBot/iTool.DiscordBot.csproj @@ -14,9 +14,8 @@ - - +