From ef824244003dfe1be6642d677b1556e02b649eae Mon Sep 17 00:00:00 2001 From: Thomas Ardal Date: Thu, 7 Nov 2024 10:36:11 +0100 Subject: [PATCH] Create installation --- src/Elmah.Io.WinUI/ElmahIoWinUI.cs | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Elmah.Io.WinUI/ElmahIoWinUI.cs b/src/Elmah.Io.WinUI/ElmahIoWinUI.cs index 171b16f..c997a9c 100644 --- a/src/Elmah.Io.WinUI/ElmahIoWinUI.cs +++ b/src/Elmah.Io.WinUI/ElmahIoWinUI.cs @@ -16,6 +16,7 @@ namespace Elmah.Io.WinUI public static class ElmahIoWinUI { internal static readonly string _assemblyVersion = typeof(ElmahIoWinUI).Assembly.GetName().Version?.ToString() ?? "Unknown"; + internal static readonly string _elmahIoClientAssemblyVersion = typeof(IElmahioAPI).Assembly.GetName().Version?.ToString() ?? "Unknown"; internal static readonly string _winUiAssemblyVersion = typeof(Application).Assembly.GetName().Version?.ToString() ?? "Unknown"; #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. @@ -56,6 +57,8 @@ public static void Init(ElmahIoWinUIOptions options) Application.Current.UnhandledException += (sender, args) => Log(args.Exception); + + CreateInstallation(); } /// @@ -150,5 +153,37 @@ private static string UserAgent() .Append(new ProductInfoHeaderValue(new ProductHeaderValue("Microsoft.WinUI", _winUiAssemblyVersion)).ToString()) .ToString(); } + + private static void CreateInstallation() + { + try + { + var loggerInfo = new LoggerInfo + { + Type = "Elmah.Io.WinUI", + Properties = [], + ConfigFiles = [], + Assemblies = + [ + new AssemblyInfo { Name = "Elmah.Io.WinUI", Version = _assemblyVersion }, + new AssemblyInfo { Name = "Elmah.Io.Client", Version = _elmahIoClientAssemblyVersion }, + new AssemblyInfo { Name = "Microsoft.WinUI", Version = _winUiAssemblyVersion } + ], + }; + + var installation = new CreateInstallation + { + Type = "windowsapp", + Name = _options.Application, + Loggers = [loggerInfo] + }; + + _logger.Installations.Create(_options.LogId.ToString(), installation); + } + catch + { + // We don't want to crash the entire application if the installation fails. Carry on. + } + } } }