Skip to content

Commit

Permalink
Merge pull request #25 from dennys/dotnet5
Browse files Browse the repository at this point in the history
Migrate Serilog to Microsoft.Extensions.Logging + NLog (for #20, #24)
  • Loading branch information
dennys authored Nov 2, 2021
2 parents aa60d4c + d20d8bc commit 6ae7d38
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
6 changes: 4 additions & 2 deletions hMoney/Apix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Serilog;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using static hMoney.Globals;
Expand All @@ -7,6 +7,8 @@ namespace hMoney
{
public class Apix
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

public DateTime GetNextTransDate(RepeatType repeatType, DateTime preTransDate, int numOccurrences)
{
DateTime nextTransDate = preTransDate;
Expand Down Expand Up @@ -79,7 +81,7 @@ public DateTime GetNextTransDate(RepeatType repeatType, DateTime preTransDate, i
}
break;
default:
Log.Error("Invalid repeat type: " + repeatType);
Logger.Error("Invalid repeat type: " + repeatType);
//TODO should raise exception here
break;
}
Expand Down
9 changes: 2 additions & 7 deletions hMoney/DB.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Serilog;
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
Expand Down Expand Up @@ -46,14 +45,10 @@ public class DB
const String CONDITION_TODAY = "Today";
const String CONDITION_RECONCILED = "Reconciled";

private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
public DB()
{
Configuration config;
// Setup log (Serilog)
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger();

// Setup configuration
config = new Configuration();
Expand Down
14 changes: 3 additions & 11 deletions hMoney/FormMain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Serilog;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -15,22 +15,14 @@ public partial class FormMain : Form
private readonly DB db;
private readonly Apix api;

private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

public FormMain()
{
// Enable configuration
config = new Configuration();
config.Init();

// Setup log (Serilog)
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger();

Log.Warning("Hello, world!");

System.Diagnostics.Debug.WriteLine("diag");

// Setup i18n
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(config.GetLanguage());
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(config.GetLanguage());
Expand Down
5 changes: 3 additions & 2 deletions hMoney/hMoney.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="ini-parser-netcore3.1" Version="3.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="NLog.Config" Version="4.7.12" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.30.0.37606">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 3 additions & 2 deletions hMoneyTests/hMoneyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="NLog.Config" Version="4.7.12" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.30.0.37606">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 3 additions & 2 deletions hMoneyVSTests/hMoneyVSTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="NLog.Config" Version="4.7.12" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.30.0.37606">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 6ae7d38

Please sign in to comment.