From ec8c6cbe3f3ec57f7614fa19454912bd7de23790 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Feb 2018 11:42:52 +0100 Subject: [PATCH] Change to NLog instead of log4net. --- .idea/.idea.Launchpad/.idea/contentModel.xml | 5 +-- .../Handlers/Manifest/ManifestHandler.cs | 36 +++++-------------- Launchpad.Common/Launchpad.Common.csproj | 1 - Launchpad.Launcher/Handlers/ChecksHandler.cs | 4 +-- Launchpad.Launcher/Handlers/GameHandler.cs | 4 +-- .../Handlers/LauncherHandler.cs | 4 +-- .../Protocols/Manifest/FTPProtocolHandler.cs | 5 ++- .../Protocols/Manifest/HTTPProtocolHandler.cs | 4 +-- .../Manifest/ManifestBasedProtocolHandler.cs | 10 +++--- .../Protocols/PatchProtocolHandler.cs | 4 +-- Launchpad.Launcher/Interface/MainWindow.cs | 4 +-- Launchpad.Launcher/Launchpad.Launcher.csproj | 7 ++-- Launchpad.Launcher/NLog.config | 22 ++++++++++++ Launchpad.Launcher/Program.cs | 10 ++---- .../Services/LocalVersionService.cs | 4 +-- Launchpad.Launcher/log4net.config | 24 ------------- .../Launchpad.Utilities.csproj | 2 +- Launchpad.Utilities/NLog.config | 24 +++++++++++++ Launchpad.Utilities/Program.cs | 10 ++---- Launchpad.Utilities/log4net.config | 24 ------------- 20 files changed, 85 insertions(+), 123 deletions(-) create mode 100644 Launchpad.Launcher/NLog.config delete mode 100644 Launchpad.Launcher/log4net.config create mode 100644 Launchpad.Utilities/NLog.config delete mode 100644 Launchpad.Utilities/log4net.config diff --git a/.idea/.idea.Launchpad/.idea/contentModel.xml b/.idea/.idea.Launchpad/.idea/contentModel.xml index 14540c08..cb5e89cd 100644 --- a/.idea/.idea.Launchpad/.idea/contentModel.xml +++ b/.idea/.idea.Launchpad/.idea/contentModel.xml @@ -249,6 +249,7 @@ + @@ -271,7 +272,7 @@ - + @@ -317,6 +318,7 @@ + @@ -330,7 +332,6 @@ - diff --git a/Launchpad.Common/Handlers/Manifest/ManifestHandler.cs b/Launchpad.Common/Handlers/Manifest/ManifestHandler.cs index 550eca24..770161ac 100644 --- a/Launchpad.Common/Handlers/Manifest/ManifestHandler.cs +++ b/Launchpad.Common/Handlers/Manifest/ManifestHandler.cs @@ -25,7 +25,6 @@ using System.IO; using Launchpad.Common.Enums; -using log4net; namespace Launchpad.Common.Handlers.Manifest { @@ -34,11 +33,6 @@ namespace Launchpad.Common.Handlers.Manifest /// public sealed class ManifestHandler { - /// - /// Logger instance for this class. - /// - private static readonly ILog Log = LogManager.GetLogger(typeof(ManifestHandler)); - private readonly object ManifestsLock = new object(); /// @@ -128,34 +122,20 @@ public void ReloadManifests(EManifestType manifestType) var oldManifestPath = GetManifestPath(manifestType, true); // Reload new manifests - try - { - if (!File.Exists(newManifestPath)) - { - this.Manifests.AddOrUpdate(manifestType, null); - } - - this.Manifests.AddOrUpdate(manifestType, LoadManifest(newManifestPath)); - } - catch (IOException ioex) + if (!File.Exists(newManifestPath)) { - Log.Warn($"Could not load manifest of type {manifestType} (IOException): " + ioex.Message); + this.Manifests.AddOrUpdate(manifestType, null); } - // Reload old manifests - try - { - if (!File.Exists(oldManifestPath)) - { - this.OldManifests.AddOrUpdate(manifestType, null); - } + this.Manifests.AddOrUpdate(manifestType, LoadManifest(newManifestPath)); - this.OldManifests.AddOrUpdate(manifestType, LoadManifest(oldManifestPath)); - } - catch (IOException ioex) + // Reload old manifests + if (!File.Exists(oldManifestPath)) { - Log.Warn($"Could not load old manifest of type {manifestType} (IOException): " + ioex.Message); + this.OldManifests.AddOrUpdate(manifestType, null); } + + this.OldManifests.AddOrUpdate(manifestType, LoadManifest(oldManifestPath)); } } diff --git a/Launchpad.Common/Launchpad.Common.csproj b/Launchpad.Common/Launchpad.Common.csproj index b379ed23..83ff73a5 100644 --- a/Launchpad.Common/Launchpad.Common.csproj +++ b/Launchpad.Common/Launchpad.Common.csproj @@ -30,6 +30,5 @@ - \ No newline at end of file diff --git a/Launchpad.Launcher/Handlers/ChecksHandler.cs b/Launchpad.Launcher/Handlers/ChecksHandler.cs index f8a01cf0..c1141bf6 100644 --- a/Launchpad.Launcher/Handlers/ChecksHandler.cs +++ b/Launchpad.Launcher/Handlers/ChecksHandler.cs @@ -26,7 +26,7 @@ using Launchpad.Launcher.Handlers.Protocols; using Launchpad.Launcher.Utility; -using log4net; +using NLog; namespace Launchpad.Launcher.Handlers { @@ -38,7 +38,7 @@ internal sealed class ChecksHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(ChecksHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); private readonly PatchProtocolHandler Patch; diff --git a/Launchpad.Launcher/Handlers/GameHandler.cs b/Launchpad.Launcher/Handlers/GameHandler.cs index 20eaa9e0..932d60c9 100644 --- a/Launchpad.Launcher/Handlers/GameHandler.cs +++ b/Launchpad.Launcher/Handlers/GameHandler.cs @@ -30,7 +30,7 @@ using Launchpad.Launcher.Handlers.Protocols; using Launchpad.Launcher.Services; using Launchpad.Launcher.Utility; -using log4net; +using NLog; namespace Launchpad.Launcher.Handlers { @@ -50,7 +50,7 @@ internal sealed class GameHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(GameHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// /// Event raised whenever the progress of installing or updating the game changes. diff --git a/Launchpad.Launcher/Handlers/LauncherHandler.cs b/Launchpad.Launcher/Handlers/LauncherHandler.cs index e2c4cede..fc4d5d72 100644 --- a/Launchpad.Launcher/Handlers/LauncherHandler.cs +++ b/Launchpad.Launcher/Handlers/LauncherHandler.cs @@ -31,7 +31,7 @@ using Launchpad.Launcher.Configuration; using Launchpad.Launcher.Handlers.Protocols; using Launchpad.Launcher.Utility; -using log4net; +using NLog; namespace Launchpad.Launcher.Handlers { @@ -51,7 +51,7 @@ internal sealed class LauncherHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(LauncherHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// /// Raised whenever the changelog finishes downloading. diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs index b4000adf..878260df 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs @@ -25,9 +25,8 @@ using System.Net; using System.Text; -using Launchpad.Common; using Launchpad.Common.Enums; -using log4net; +using NLog; using SixLabors.ImageSharp; namespace Launchpad.Launcher.Handlers.Protocols.Manifest @@ -43,7 +42,7 @@ internal sealed class FTPProtocolHandler : ManifestBasedProtocolHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(FTPProtocolHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// public override bool CanPatch() diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs index 98d64c4f..80d5a4cb 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs @@ -27,7 +27,7 @@ using Launchpad.Common; using Launchpad.Common.Enums; -using log4net; +using NLog; using SixLabors.ImageSharp; using Image = SixLabors.ImageSharp.Image; @@ -42,7 +42,7 @@ internal sealed class HTTPProtocolHandler : ManifestBasedProtocolHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(HTTPProtocolHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// public override bool CanPatch() diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs index 6e985424..17504092 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs @@ -31,8 +31,8 @@ using Launchpad.Common.Handlers.Manifest; using Launchpad.Launcher.Services; using Launchpad.Launcher.Utility; -using log4net; using NGettext; +using NLog; namespace Launchpad.Launcher.Handlers.Protocols.Manifest { @@ -42,14 +42,14 @@ namespace Launchpad.Launcher.Handlers.Protocols.Manifest public abstract class ManifestBasedProtocolHandler : PatchProtocolHandler { /// - /// The localization catalog. + /// Logger instance for this class. /// - private static readonly ICatalog LocalizationCatalog = new Catalog("Launchpad", "./Content/locale"); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// - /// Logger instance for this class. + /// The localization catalog. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(ManifestBasedProtocolHandler)); + private static readonly ICatalog LocalizationCatalog = new Catalog("Launchpad", "./Content/locale"); private readonly LocalVersionService LocalVersionService = new LocalVersionService(); diff --git a/Launchpad.Launcher/Handlers/Protocols/PatchProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/PatchProtocolHandler.cs index f3611e0b..3edaefc5 100644 --- a/Launchpad.Launcher/Handlers/Protocols/PatchProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/PatchProtocolHandler.cs @@ -26,7 +26,7 @@ using Launchpad.Common.Enums; using Launchpad.Launcher.Configuration; using Launchpad.Launcher.Services; -using log4net; +using NLog; using SixLabors.ImageSharp; namespace Launchpad.Launcher.Handlers.Protocols @@ -46,7 +46,7 @@ public abstract class PatchProtocolHandler /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(PatchProtocolHandler)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// /// Gets the config handler reference. diff --git a/Launchpad.Launcher/Interface/MainWindow.cs b/Launchpad.Launcher/Interface/MainWindow.cs index e6b556bc..a8ccf8f8 100644 --- a/Launchpad.Launcher/Interface/MainWindow.cs +++ b/Launchpad.Launcher/Interface/MainWindow.cs @@ -34,9 +34,9 @@ using Launchpad.Launcher.Services; using Launchpad.Launcher.Utility; using Launchpad.Launcher.Utility.Enums; -using log4net; using NGettext; +using NLog; using SixLabors.ImageSharp; using Application = Gtk.Application; using Process = System.Diagnostics.Process; @@ -53,7 +53,7 @@ public sealed partial class MainWindow : Gtk.Window /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(MainWindow)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); private readonly LocalVersionService LocalVersionService = new LocalVersionService(); diff --git a/Launchpad.Launcher/Launchpad.Launcher.csproj b/Launchpad.Launcher/Launchpad.Launcher.csproj index 95348a97..52fd1de0 100644 --- a/Launchpad.Launcher/Launchpad.Launcher.csproj +++ b/Launchpad.Launcher/Launchpad.Launcher.csproj @@ -30,17 +30,14 @@ true - - - + - @@ -48,7 +45,7 @@ - + PreserveNewest diff --git a/Launchpad.Launcher/NLog.config b/Launchpad.Launcher/NLog.config new file mode 100644 index 00000000..d7f650ad --- /dev/null +++ b/Launchpad.Launcher/NLog.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Launchpad.Launcher/Program.cs b/Launchpad.Launcher/Program.cs index b63c1a4a..7dc7fed2 100644 --- a/Launchpad.Launcher/Program.cs +++ b/Launchpad.Launcher/Program.cs @@ -31,8 +31,7 @@ using Launchpad.Launcher.Interface; using Launchpad.Launcher.Services; using Launchpad.Launcher.Utility; -using log4net; -using FileInfo = System.IO.FileInfo; +using NLog; using Task = System.Threading.Tasks.Task; using Timeout = GLib.Timeout; @@ -46,7 +45,7 @@ public static class Program /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(Program)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); private static readonly LocalVersionService LocalVersionService = new LocalVersionService(); @@ -66,11 +65,6 @@ private static void Main() Environment.SetEnvironmentVariable("GSETTINGS_SCHEMA_DIR", "share\\glib-2.0\\schemas\\"); } - var logRepo = LogManager.GetRepository(Assembly.GetEntryAssembly()); - var fileInfo = new FileInfo("log4net.config"); - log4net.Config.XmlConfigurator.Configure(logRepo, fileInfo); - - Log.Info("----------------"); Log.Info($"Launchpad v{LocalVersionService.GetLocalLauncherVersion()} starting..."); var systemBitness = Environment.Is64BitOperatingSystem ? "x64" : "x86"; diff --git a/Launchpad.Launcher/Services/LocalVersionService.cs b/Launchpad.Launcher/Services/LocalVersionService.cs index 7c1853dc..4bcfce1a 100644 --- a/Launchpad.Launcher/Services/LocalVersionService.cs +++ b/Launchpad.Launcher/Services/LocalVersionService.cs @@ -24,7 +24,7 @@ using System.IO; using Launchpad.Launcher.Utility; -using log4net; +using NLog; namespace Launchpad.Launcher.Services { @@ -36,7 +36,7 @@ public class LocalVersionService /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(LocalVersionService)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// /// Gets the local game version. diff --git a/Launchpad.Launcher/log4net.config b/Launchpad.Launcher/log4net.config deleted file mode 100644 index d314243b..00000000 --- a/Launchpad.Launcher/log4net.config +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Launchpad.Utilities/Launchpad.Utilities.csproj b/Launchpad.Utilities/Launchpad.Utilities.csproj index 642e5983..8218a19e 100644 --- a/Launchpad.Utilities/Launchpad.Utilities.csproj +++ b/Launchpad.Utilities/Launchpad.Utilities.csproj @@ -30,7 +30,7 @@ - + diff --git a/Launchpad.Utilities/NLog.config b/Launchpad.Utilities/NLog.config new file mode 100644 index 00000000..58bcaa2f --- /dev/null +++ b/Launchpad.Utilities/NLog.config @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Launchpad.Utilities/Program.cs b/Launchpad.Utilities/Program.cs index c14e3811..49e6984b 100644 --- a/Launchpad.Utilities/Program.cs +++ b/Launchpad.Utilities/Program.cs @@ -21,7 +21,6 @@ using System; using System.IO; -using System.Reflection; using System.Threading; using CommandLine; using GLib; @@ -29,10 +28,9 @@ using Launchpad.Utilities.Utility.Events; using Launchpad.Utilities.Interface; using Launchpad.Utilities.Options; -using log4net; using Launchpad.Common.Enums; +using NLog; using Application = Gtk.Application; -using FileInfo = System.IO.FileInfo; using Task = System.Threading.Tasks.Task; namespace Launchpad.Utilities @@ -42,17 +40,13 @@ internal static class Program /// /// Logger instance for this class. /// - private static readonly ILog Log = LogManager.GetLogger(typeof(Program)); + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); /// /// The main entry point for the application. /// private static async Task Main(string[] args) { - var logRepo = LogManager.GetRepository(Assembly.GetEntryAssembly()); - var fileInfo = new FileInfo("log4net.config"); - log4net.Config.XmlConfigurator.Configure(logRepo, fileInfo); - var options = new CLIOptions(); Parser.Default.ParseArguments(args) .WithParsed(r => options = r); diff --git a/Launchpad.Utilities/log4net.config b/Launchpad.Utilities/log4net.config deleted file mode 100644 index d314243b..00000000 --- a/Launchpad.Utilities/log4net.config +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file