diff --git a/CompatBot/Commands/Sudo.cs b/CompatBot/Commands/Sudo.cs index a7629b9a..1ff2ffe6 100644 --- a/CompatBot/Commands/Sudo.cs +++ b/CompatBot/Commands/Sudo.cs @@ -108,18 +108,20 @@ namespace CompatBot.Commands { try { - using (var log = File.Open(Config.LogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - using (var result = new MemoryStream((int)Math.Min(Config.AttachmentSizeLimit, log.Length))) + var logPath = Config.CurrentLogPath; + var attachmentSizeLimit = Config.AttachmentSizeLimit; + using (var log = File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var result = new MemoryStream((int)Math.Min(attachmentSizeLimit, log.Length))) { using (var gzip = new GZipStream(result, CompressionLevel.Optimal, true)) { await log.CopyToAsync(gzip, Config.Cts.Token).ConfigureAwait(false); await gzip.FlushAsync().ConfigureAwait(false); } - if (result.Length <= Config.AttachmentSizeLimit) + if (result.Length <= attachmentSizeLimit) { result.Seek(0, SeekOrigin.Begin); - await ctx.RespondWithFileAsync(Path.GetFileName(Config.LogPath) + ".gz", result).ConfigureAwait(false); + await ctx.RespondWithFileAsync(Path.GetFileName(logPath) + ".gz", result).ConfigureAwait(false); } else await ctx.ReactWithAsync(Config.Reactions.Failure, "Compressed log size is too large, ask Nicba for help :(", true).ConfigureAwait(false); diff --git a/CompatBot/Config.cs b/CompatBot/Config.cs index 6ace1493..2a64aa59 100644 --- a/CompatBot/Config.cs +++ b/CompatBot/Config.cs @@ -55,9 +55,11 @@ namespace CompatBot public static int MinimumPiracyTriggerLength => config.GetValue(nameof(MinimumPiracyTriggerLength), 4); public static string Token => config.GetValue(nameof(Token), ""); - public static string LogPath => config.GetValue(nameof(LogPath), "../../../logs/"); // paths are relative to the assembly, so this will put it in the project's root + public static string LogPath => config.GetValue(nameof(LogPath), "./logs/"); // paths are relative to the working directory public static string IrdCachePath => config.GetValue(nameof(IrdCachePath), "./ird/"); + internal static string CurrentLogPath => Path.GetFullPath(Path.Combine(LogPath, "bot.log")); + public static string GoogleApiConfigPath { get @@ -177,7 +179,7 @@ namespace CompatBot { var config = new NLog.Config.LoggingConfiguration(); var fileTarget = new FileTarget("logfile") { - FileName = Path.Combine(LogPath, "bot.log"), + FileName = CurrentLogPath, ArchiveEvery = FileArchivePeriod.Day, ArchiveNumbering = ArchiveNumberingMode.DateAndSequence, KeepFileOpen = true,