Skip to content

Commit

Permalink
Change to NLog instead of log4net.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Feb 2, 2018
1 parent ac81a35 commit ec8c6cb
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 123 deletions.
5 changes: 3 additions & 2 deletions .idea/.idea.Launchpad/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 8 additions & 28 deletions Launchpad.Common/Handlers/Manifest/ManifestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using System.IO;

using Launchpad.Common.Enums;
using log4net;

namespace Launchpad.Common.Handlers.Manifest
{
Expand All @@ -34,11 +33,6 @@ namespace Launchpad.Common.Handlers.Manifest
/// </summary>
public sealed class ManifestHandler
{
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(ManifestHandler));

private readonly object ManifestsLock = new object();

/// <summary>
Expand Down Expand Up @@ -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));
}
}

Expand Down
1 change: 0 additions & 1 deletion Launchpad.Common/Launchpad.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="all" />
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Handlers/ChecksHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using Launchpad.Launcher.Handlers.Protocols;

using Launchpad.Launcher.Utility;
using log4net;
using NLog;

namespace Launchpad.Launcher.Handlers
{
Expand All @@ -38,7 +38,7 @@ internal sealed class ChecksHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(ChecksHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

private readonly PatchProtocolHandler Patch;

Expand Down
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Handlers/GameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -50,7 +50,7 @@ internal sealed class GameHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(GameHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <summary>
/// Event raised whenever the progress of installing or updating the game changes.
Expand Down
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Handlers/LauncherHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -51,7 +51,7 @@ internal sealed class LauncherHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(LauncherHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <summary>
/// Raised whenever the changelog finishes downloading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +42,7 @@ internal sealed class FTPProtocolHandler : ManifestBasedProtocolHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(FTPProtocolHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <inheritdoc />
public override bool CanPatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

using Launchpad.Common;
using Launchpad.Common.Enums;
using log4net;
using NLog;
using SixLabors.ImageSharp;
using Image = SixLabors.ImageSharp.Image;

Expand All @@ -42,7 +42,7 @@ internal sealed class HTTPProtocolHandler : ManifestBasedProtocolHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(HTTPProtocolHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <inheritdoc />
public override bool CanPatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -42,14 +42,14 @@ namespace Launchpad.Launcher.Handlers.Protocols.Manifest
public abstract class ManifestBasedProtocolHandler : PatchProtocolHandler
{
/// <summary>
/// The localization catalog.
/// Logger instance for this class.
/// </summary>
private static readonly ICatalog LocalizationCatalog = new Catalog("Launchpad", "./Content/locale");
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <summary>
/// Logger instance for this class.
/// The localization catalog.
/// </summary>
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();

Expand Down
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Handlers/Protocols/PatchProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +46,7 @@ public abstract class PatchProtocolHandler
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(PatchProtocolHandler));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <summary>
/// Gets the config handler reference.
Expand Down
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Interface/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,7 +53,7 @@ public sealed partial class MainWindow : Gtk.Window
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(MainWindow));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

private readonly LocalVersionService LocalVersionService = new LocalVersionService();

Expand Down
7 changes: 2 additions & 5 deletions Launchpad.Launcher/Launchpad.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,22 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Prefer32bit>true</Prefer32bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Config.Net" Version="4.7.0.89" />
<PackageReference Include="GtkSharp" Version="3.22.24.29" />
<PackageReference Include="GtkSharp.Win32" Version="3.1.2" />
<PackageReference Include="NLog" Version="4.4.12" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0002" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="all" />
<PackageReference Include="NGettext" Version="0.6.3" />
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="app.manifest" />
<EmbeddedResource Include="Resources\**\*.*" />
<EmbeddedResource Include="Interface\Launchpad.glade" />
</ItemGroup>
<ItemGroup>
<Content Include="log4net.config">
<Content Include="*.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\locale\**\*.po">
Expand Down
22 changes: 22 additions & 0 deletions Launchpad.Launcher/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogFile="launchpad-internal.log"
internalLogLevel="Info" >

<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="target1" fileName="launchpad.log"
layout="${date} | ${logger:shortName=True} | ${level:uppercase=true} | ${message} ${exception}|${all-event-properties}" />
<target xsi:type="ColoredConsole" name="target2"
layout="${date} | ${logger:shortName=True} | ${level:uppercase=true} | ${message} ${exception}|${all-event-properties}" />
</targets>

<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="target1,target2" />
</rules>
</nlog>
10 changes: 2 additions & 8 deletions Launchpad.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,7 +45,7 @@ public static class Program
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

private static readonly LocalVersionService LocalVersionService = new LocalVersionService();

Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions Launchpad.Launcher/Services/LocalVersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using System.IO;

using Launchpad.Launcher.Utility;
using log4net;
using NLog;

namespace Launchpad.Launcher.Services
{
Expand All @@ -36,7 +36,7 @@ public class LocalVersionService
/// <summary>
/// Logger instance for this class.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(LocalVersionService));
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

/// <summary>
/// Gets the local game version.
Expand Down
24 changes: 0 additions & 24 deletions Launchpad.Launcher/log4net.config

This file was deleted.

2 changes: 1 addition & 1 deletion Launchpad.Utilities/Launchpad.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PackageReference Include="GtkSharp.Win32" Version="3.1.2" />
<PackageReference Include="CommandLineParser" Version="2.2.1" />
<PackageReference Include="NGettext" Version="0.6.3" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="NLog" Version="4.4.12" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Interface\Launchpad.Utilities.glade" />
Expand Down
Loading

0 comments on commit ec8c6cb

Please sign in to comment.