Logging and UI improvements

This commit is contained in:
zone117x
2015-04-19 01:04:08 -06:00
parent 010135da85
commit 58ea700d37
11 changed files with 12759 additions and 27 deletions

View File

@@ -1,4 +1,7 @@
using System;
using NLog;
using NLog.Config;
using NLog.Targets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -6,6 +9,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Jackett
{
@@ -13,27 +17,59 @@ namespace Jackett
{
public static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett");
public static ManualResetEvent ExitEvent = new ManualResetEvent(false);
public static Server ServerInstance { get; private set; }
public static bool IsFirstRun { get; private set; }
public static Logger LoggerInstance { get; private set; }
static void Main(string[] args)
{
try
{
if (!Directory.Exists(AppConfigDirectory))
{
IsFirstRun = true;
Directory.CreateDirectory(AppConfigDirectory);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("Could not create settings directory");
MessageBox.Show("Could not create settings directory.");
Application.Exit();
return;
}
var logConfig = new LoggingConfiguration();
var logFile = new FileTarget();
logConfig.AddTarget("file", logFile);
logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt");
logFile.Layout = "${longdate} ${level} ${message}";
var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile);
var logAlert = new MessageBoxTarget();
logConfig.AddTarget("alert", logAlert);
logAlert.Layout = "${message}";
logAlert.Caption = "Alert";
var logAlertRule = new LoggingRule("*", LogLevel.Error, logAlert);
logConfig.LoggingRules.Add(logFileRule);
logConfig.LoggingRules.Add(logAlertRule);
LogManager.Configuration = logConfig;
LoggerInstance = LogManager.GetCurrentClassLogger();
Task.Run(() =>
{
var server = new Server();
server.Start();
ServerInstance = new Server();
ServerInstance.Start();
});
ExitEvent.WaitOne();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
}
}
}