Skip to content

Commit 62e8a1b

Browse files
authored
Feature: Log program update check & errors (BornToBeRoot#2329)
* Feature: Log program update check & errors * Docs: BornToBeRoot#2329
1 parent d3cde25 commit 62e8a1b

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

Source/NETworkManager.Update/NETworkManager.Update.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
</PropertyGroup>
1515
<!-- Target 6.0.0 for compatibility https://github.com/dotnet/core/issues/7176 -->
1616
<ItemGroup>
17-
<FrameworkReference
18-
Update="Microsoft.WindowsDesktop.App;Microsoft.WindowsDesktop.App.WPF;Microsoft.WindowsDesktop.App.WindowsForms"
19-
TargetingPackVersion="6.0.0" />
17+
<FrameworkReference Update="Microsoft.WindowsDesktop.App;Microsoft.WindowsDesktop.App.WPF;Microsoft.WindowsDesktop.App.WindowsForms" TargetingPackVersion="6.0.0" />
2018
</ItemGroup>
2119
<ItemGroup>
2220
<Compile Include="..\GlobalAssemblyInfo.cs" Link="Properties\GlobalAssemblyInfo.cs" />
2321
</ItemGroup>
2422
<ItemGroup>
23+
<PackageReference Include="log4net" Version="2.0.15" />
2524
<PackageReference Include="Octokit" Version="6.0.0" />
2625
</ItemGroup>
2726
</Project>

Source/NETworkManager.Update/UpdateAvailableArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class UpdateAvailableArgs : EventArgs
1414
public Release Release { get; private set; }
1515

1616
/// <summary>
17-
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class and passes the <see cref="Release"/> as paramter.
17+
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class with parameters.
1818
/// </summary>
1919
/// <param name="release">Release of the program update.</param>
2020
public UpdateAvailableArgs(Release release)

Source/NETworkManager.Update/Updater.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
3+
using log4net;
34
using Octokit;
45

56
namespace NETworkManager.Update;
@@ -9,6 +10,8 @@ namespace NETworkManager.Update;
910
/// </summary>
1011
public class Updater
1112
{
13+
private static readonly ILog _log = LogManager.GetLogger(typeof(Updater));
14+
1215
#region Events
1316
/// <summary>
1417
/// Is triggered when update check is complete and an update is available.
@@ -45,6 +48,7 @@ protected virtual void OnNoUpdateAvailable()
4548
/// <summary>
4649
/// Triggers the <see cref="Error"/> event.
4750
/// </summary>
51+
/// <param name="e">Passes <see cref="UpdateErrorArgs"/> to the event.</param>
4852
protected virtual void OnError()
4953
{
5054
Error?.Invoke(this, EventArgs.Empty);
@@ -64,6 +68,8 @@ public void CheckOnGitHub(string userName, string projectName, Version currentVe
6468
{
6569
try
6670
{
71+
_log.Info("Checking for new program version on GitHub...");
72+
6773
var client = new GitHubClient(new ProductHeaderValue(userName + "_" + projectName));
6874

6975
Release release = null;
@@ -75,12 +81,19 @@ public void CheckOnGitHub(string userName, string projectName, Version currentVe
7581

7682
// Compare versions (tag=2021.2.15.0, version=2021.2.15.0)
7783
if (new Version(release.TagName) > currentVersion)
84+
{
85+
_log.Info($"New version \"{release.TagName}\" is available on GitHub!");
7886
OnUpdateAvailable(new UpdateAvailableArgs(release));
87+
}
7988
else
89+
{
90+
_log.Info("No new program version available on GitHub!");
8091
OnNoUpdateAvailable();
92+
}
8193
}
82-
catch
94+
catch (Exception ex)
8395
{
96+
_log.Error("Error while checking for new program version on GitHub!", ex);
8497
OnError();
8598
}
8699
});

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,17 +1175,10 @@ private void ProfileManager_OnLoadedProfileFileChangedEvent(object sender, Profi
11751175
private void CheckForUpdates()
11761176
{
11771177
var updater = new Updater();
1178-
11791178
updater.UpdateAvailable += Updater_UpdateAvailable;
1180-
updater.Error += Updater_Error;
11811179
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version, SettingsManager.Current.Update_CheckForPreReleases);
11821180
}
11831181

1184-
private static void Updater_Error(object sender, EventArgs e)
1185-
{
1186-
// Log
1187-
}
1188-
11891182
private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
11901183
{
11911184
UpdateReleaseUrl = e.Release.Prerelease ? e.Release.HtmlUrl : Properties.Resources.NETworkManager_LatestReleaseUrl;

docs/Changelog/next-release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Breaking changes
4343
- Profile dialog
4444
- Show an error next to the tab if the settings on the page contain errors [#2309](https://github.com/BornToBeRoot/NETworkManager/pull/2309){:target="\_blank"}
4545
- SNMP options are now validates (same as group) [#2309](https://github.com/BornToBeRoot/NETworkManager/pull/2309){:target="\_blank"}
46+
- Log program update check & errors to the log file [#2329](https://github.com/BornToBeRoot/NETworkManager/pull/2329){:target="\_blank"}
4647

4748
## Bugfixes
4849

0 commit comments

Comments
 (0)