From 59cf8c3e9f7797ea9f3d5823f7bd11ca25285d34 Mon Sep 17 00:00:00 2001 From: zone117x Date: Sun, 26 Apr 2015 00:21:36 -0600 Subject: [PATCH] Fixed log file issues --- src/Jackett/Indexers/ThePirateBay.cs | 1 - src/Jackett/Program.cs | 7 ++++++- src/Jackett/Server.cs | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Jackett/Indexers/ThePirateBay.cs b/src/Jackett/Indexers/ThePirateBay.cs index 443f2c173..f7c55191d 100644 --- a/src/Jackett/Indexers/ThePirateBay.cs +++ b/src/Jackett/Indexers/ThePirateBay.cs @@ -131,7 +131,6 @@ namespace Jackett.Indexers else { var response = await CurlHelper.GetAsync(baseUrl + SwitchSingleViewUrl, null, episodeSearchUrl); - //var response = await CurlHelper.GetAsync (episodeSearchUrl, setLayoutResponse.CookieHeader); results = Encoding.UTF8.GetString(response.Content); } diff --git a/src/Jackett/Program.cs b/src/Jackett/Program.cs index 13790b176..b8a115d57 100644 --- a/src/Jackett/Program.cs +++ b/src/Jackett/Program.cs @@ -52,8 +52,13 @@ namespace Jackett var logFile = new FileTarget(); logConfig.AddTarget("file", logFile); - logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt"); logFile.Layout = "${longdate} ${level} ${message} \n ${exception:format=ToString}\n"; + logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt"); + logFile.ArchiveFileName = "log.{#####}.txt"; + logFile.ArchiveAboveSize = 500000; + logFile.MaxArchiveFiles = 1; + logFile.KeepFileOpen = false; + logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence; var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile); logConfig.LoggingRules.Add(logFileRule); diff --git a/src/Jackett/Server.cs b/src/Jackett/Server.cs index a83a3f1a1..516d6cfc8 100644 --- a/src/Jackett/Server.cs +++ b/src/Jackett/Server.cs @@ -34,8 +34,6 @@ namespace Jackett sonarrApi = new SonarrApi(); webApi = new WebApi(indexerManager, sonarrApi); - listener = new HttpListener(); - listener.Prefixes.Add("http://*:9117/"); } void LoadApiKey() @@ -56,6 +54,8 @@ namespace Jackett try { + listener = new HttpListener(); + listener.Prefixes.Add("http://*:9117/"); listener.Start(); } catch (HttpListenerException ex) @@ -101,15 +101,26 @@ namespace Jackett while (true) { + Exception error = null; try { + error = null; var context = await listener.GetContextAsync(); ProcessHttpRequest(context); } + catch (ObjectDisposedException ex) + { + Program.LoggerInstance.ErrorException("Critical error, HTTP listener was destroyed", ex); + Process.GetCurrentProcess().Kill(); + } catch (Exception ex) { + error = ex; Program.LoggerInstance.ErrorException("Error processing HTTP request", ex); } + + if (error != null) + await Task.Delay(TimeSpan.FromSeconds(5)); } }