diff --git a/SharpFM.App/App.axaml.cs b/SharpFM.App/App.axaml.cs index 7b0d262..aa4cbc6 100644 --- a/SharpFM.App/App.axaml.cs +++ b/SharpFM.App/App.axaml.cs @@ -2,11 +2,15 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using SharpFM.App.ViewModels; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace SharpFM.App; public partial class App : Application { + ILogger logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger(); + public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -18,7 +22,7 @@ public override void OnFrameworkInitializationCompleted() { desktop.MainWindow = new MainWindow { - DataContext = new MainWindowViewModel() + DataContext = new MainWindowViewModel(logger) }; } diff --git a/SharpFM.App/SharpFM.App.csproj b/SharpFM.App/SharpFM.App.csproj index 9f0d738..3ed9b97 100644 --- a/SharpFM.App/SharpFM.App.csproj +++ b/SharpFM.App/SharpFM.App.csproj @@ -43,6 +43,11 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + + + + diff --git a/SharpFM.App/ViewModels/MainWindowViewModel.cs b/SharpFM.App/ViewModels/MainWindowViewModel.cs index a244318..c306375 100644 --- a/SharpFM.App/ViewModels/MainWindowViewModel.cs +++ b/SharpFM.App/ViewModels/MainWindowViewModel.cs @@ -7,6 +7,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using FluentAvalonia.UI.Data; +using Microsoft.Extensions.Logging; using SharpFM.App.Models; using SharpFM.Core; @@ -14,7 +15,9 @@ namespace SharpFM.App.ViewModels; public partial class MainWindowViewModel : INotifyPropertyChanged { - public ClipDbContext _context; + private readonly ILogger _logger; + + public readonly ClipDbContext _context; public event PropertyChangedEventHandler? PropertyChanged; @@ -23,12 +26,14 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - public MainWindowViewModel() + public MainWindowViewModel(ILogger logger) { + _logger = logger; + _context = new ClipDbContext(); _context.Database.EnsureCreated(); - Console.WriteLine($"Database path: {_context.DbPath}."); + _logger.LogInformation($"Database path: {_context.DbPath}."); FileMakerClips = new ObservableCollection(); @@ -104,6 +109,7 @@ public void NewEmptyItem() } catch (Exception e) { + _logger.LogCritical("Error creating new Clip.", e); } } @@ -129,6 +135,7 @@ public void CopyAsClass() } catch (Exception e) { + _logger.LogCritical("Error Copying as Class.", e); } } @@ -171,6 +178,7 @@ public async Task PasteFileMakerClipData() } catch (Exception e) { + _logger.LogCritical("Error translating FileMaker blob to Xml.", e); } } @@ -196,6 +204,7 @@ public async Task CopySelectedToClip() } catch (Exception e) { + _logger.LogCritical("Error returning the selected Clip FileMaker blob format.", e); } } diff --git a/SharpFM.App/nlog.config b/SharpFM.App/nlog.config new file mode 100644 index 0000000..a30671f --- /dev/null +++ b/SharpFM.App/nlog.config @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file