Skip to content

Commit

Permalink
chore: Added logging to auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorixon committed Jul 11, 2024
1 parent 86a96e5 commit 86f0697
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/JASM.AutoUpdater/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Linq;
using Microsoft.UI.Xaml;
using Serilog;
using WinUIEx;
using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -20,6 +22,16 @@ public partial class App : Application
public App()
{
InitializeComponent();


var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Information()
.WriteTo.File("logs\\auto-updater-log.txt")
.WriteTo.Console()
.CreateLogger();

Log.Logger = logger;
}

/// <summary>
Expand All @@ -28,6 +40,8 @@ public App()
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Log.Information("AutoUpdater OnLaunched");

MainWindow = new MainWindow();
MainWindow.Activate();
MainWindow.SetWindowSize(900, 600);
Expand All @@ -41,6 +55,12 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
MainWindow.Content = new MainPage(arguments.Skip(1).FirstOrDefault() ?? string.Empty);
MainWindow.BringToFront();

UnhandledException += OnUnhandledException;
}

private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.Error(e.Exception, "Unhandled exception");
}

internal static MainWindow MainWindow;
Expand Down
3 changes: 3 additions & 0 deletions src/JASM.AutoUpdater/JASM.AutoUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="WinUIEx" Version="2.3.4" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/JASM.AutoUpdater/MainPageVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ private void CleanUp()

private async Task<ApiGitHubRelease?> GetLatestVersionAsync(CancellationToken cancellationToken)
{
Serilog.Log.Information("Checking for latest version...");

using var httpClient = CreateHttpClient();

var result = await httpClient.GetAsync(ReleasesApiUrl, cancellationToken);
Expand Down Expand Up @@ -446,6 +448,9 @@ private class GitHubRelease

private void Log(string logMessage, string? footer = null)
{
Serilog.Log.Information("Install Step {StepIndex} | Msg: {Message} | footer: {Footer}", (ProgressLog.Count + 1),
logMessage, footer);

var logEntry = new LogEntry
{
Message = logMessage,
Expand Down

0 comments on commit 86f0697

Please sign in to comment.