AppCenter to AppInsights migration. (#562)

* Remove AppCenter usage and libraries.

* Remove redundant pacakges and add the app insights sink.

* Diagnostic id support and manipulating telemetries.

* Handling of appdomain unhandled exceptions.

* Remove unused package identity package from mail project.

* Fixing printing.
This commit is contained in:
Burak Kaan Köse
2025-02-16 01:44:41 +01:00
committed by GitHub
parent f0e513bf0d
commit c1336428dc
27 changed files with 160 additions and 134 deletions

View File

@@ -229,6 +229,12 @@ namespace Wino.Core.UWP.Services
set => SaveProperty(propertyName: nameof(ServerTerminationBehavior), value);
}
public string DiagnosticId
{
get => _configurationService.Get(nameof(DiagnosticId), Guid.NewGuid().ToString());
set => SaveProperty(propertyName: nameof(DiagnosticId), value);
}
public DayOfWeek FirstDayOfWeek
{
get => _configurationService.Get(nameof(FirstDayOfWeek), DayOfWeek.Monday);

View File

@@ -9,6 +9,7 @@
<SolidColorBrush x:Key="FolderSyncBrush">#1abc9c</SolidColorBrush>
<SolidColorBrush x:Key="DiagnosticIdCopyBrush">#ff7675</SolidColorBrush>
<SolidColorBrush x:Key="AliasUnverifiedBrush">#ff7675</SolidColorBrush>
<SolidColorBrush x:Key="AliasVerifiedBrush">#1abc9c</SolidColorBrush>

View File

@@ -98,7 +98,6 @@
<PackageReference Include="CommunityToolkit.Uwp.Extensions" />
<PackageReference Include="CommunityToolkit.WinUI.Notifications" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.TabbedCommandBar" />
<PackageReference Include="Microsoft.AppCenter.Analytics" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" />
<PackageReference Include="Win2D.uwp" />
<PackageReference Include="EmailValidation" />

View File

@@ -3,9 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Microsoft.Extensions.DependencyInjection;
using Nito.AsyncEx;
using Serilog;
@@ -40,24 +37,16 @@ namespace Wino.Core.UWP
protected IDatabaseService DatabaseService { get; }
protected ITranslationService TranslationService { get; }
// Order matters.
private List<IInitializeAsync> initializeServices => new List<IInitializeAsync>()
{
DatabaseService,
TranslationService,
ThemeService,
};
public abstract string AppCenterKey { get; }
protected WinoApplication()
{
ConfigureAppCenter();
ConfigurePrelaunch();
Services = ConfigureServices();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
UnhandledException += OnAppUnhandledException;
Resuming += OnResuming;
Suspending += OnSuspending;
@@ -77,6 +66,18 @@ namespace Wino.Core.UWP
ConfigureLogging();
}
private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
=> Log.Fatal(e.ExceptionObject as Exception, "AppDomain Unhandled Exception");
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
=> Log.Error(e.Exception, "Unobserved Task Exception");
private void OnAppUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
Log.Fatal(e.Exception, "Unhandled Exception");
e.Handled = true;
}
protected abstract void OnApplicationCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e);
protected abstract IEnumerable<ActivationHandler> GetActivationHandlers();
protected abstract ActivationHandler<IActivatedEventArgs> GetDefaultActivationHandler();
@@ -208,29 +209,12 @@ namespace Wino.Core.UWP
catch { }
}
private void ConfigurePrelaunch()
{
if (ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch"))
CoreApplication.EnablePrelaunch(true);
}
private void OnAppUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
var parameters = new Dictionary<string, string>()
{
{ "BaseMessage", e.Exception.GetBaseException().Message },
{ "BaseStackTrace", e.Exception.GetBaseException().StackTrace },
{ "StackTrace", e.Exception.StackTrace },
{ "Message", e.Exception.Message },
};
Log.Error(e.Exception, "[Wino Crash]");
Crashes.TrackError(e.Exception, parameters);
Analytics.TrackEvent("Wino Crashed", parameters);
}
public virtual async void OnResuming(object sender, object e)
@@ -255,8 +239,6 @@ namespace Wino.Core.UWP
public virtual void OnSuspending(object sender, SuspendingEventArgs e) { }
public abstract IServiceProvider ConfigureServices();
public void ConfigureAppCenter()
=> AppCenter.Start(AppCenterKey, typeof(Analytics), typeof(Crashes));
public void ConfigureLogging()
{