try to fix log path issues

This commit is contained in:
13xforever
2019-09-23 20:01:38 +05:00
parent eea0794fae
commit e9c60086ee
2 changed files with 10 additions and 6 deletions

View File

@@ -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);

View File

@@ -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,