Skip to content

Commit

Permalink
BookLib: add shortcut CTRL+SHIFT+L to open log file
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Dec 23, 2023
1 parent e4b2b8f commit 48b0dec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public App()
var layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss.ff} [${level:format=FirstCharacter}] ${processid} ${logger} ${message} ${exception}";
var fileTarget = c.ForTarget("fileTarget").WriteTo(new FileTarget
{
FileName = Path.Combine(AppDataPath, "Log", "BookLibrary.log"),
FileName = LogFileName,
Layout = layout,
ConcurrentWrites = true,
ArchiveAboveSize = 5_000_000, // 5 MB
Expand All @@ -62,10 +62,12 @@ public App()

private static string AppDataPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ApplicationInfo.ProductName);

public static string LogFileName { get; } = Path.Combine(AppDataPath, "Log", "BookLibrary.log");

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Log.App.Info("{0} {1} is starting; OS: {2}", ApplicationInfo.ProductName, ApplicationInfo.Version, Environment.OSVersion);
Log.App.Info("{0} {1} is starting; OS: {2}; .NET: {3}", ApplicationInfo.ProductName, ApplicationInfo.Version, Environment.OSVersion, Environment.Version);

#if (!DEBUG)
DispatcherUnhandledException += AppDispatcherUnhandledException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

[assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "~F:Waf.BookLibrary.Library.Presentation.Views.ShellWindow.personViewPresenter")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "~F:Waf.BookLibrary.Library.Presentation.Views.ShellWindow.bookViewPresenter")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "BookList", Scope = "type", Target = "~T:Waf.BookLibrary.Library.Presentation.Views.BookListView")]
Expand All @@ -17,4 +18,4 @@
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Presentation.App.#ctor")]
[assembly: SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Presentation.DesignData.MockSettingsService.RaiseErrorOccurred(System.Waf.Applications.Services.SettingsErrorEventArgs)")]
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Presentation.App.OnStartup(System.Windows.StartupEventArgs)")]
[assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Presentation.App.OnStartup(System.Windows.StartupEventArgs)")]
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Window x:Class="Waf.BookLibrary.Library.Presentation.Views.ShellWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:waf="http://waf.codeplex.com/schemas"
xmlns:p="clr-namespace:Waf.BookLibrary.Library.Presentation.Properties"
xmlns:c="clr-namespace:Waf.BookLibrary.Library.Presentation.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dd="clr-namespace:Waf.BookLibrary.Library.Presentation.DesignData"
Expand All @@ -16,6 +14,7 @@
<Window.InputBindings>
<KeyBinding Command="{Binding SaveCommand}" Key="S" Modifiers="Control"/>
<KeyBinding Command="{Binding AboutCommand}" Key="F1"/>
<KeyBinding x:Name="showLogKeyBinding" Key="L" Modifiers="Control+Shift"/>
</Window.InputBindings>

<DockPanel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Waf.Applications;
using System.Windows;
using Waf.BookLibrary.Library.Applications.Views;

Expand All @@ -10,6 +12,7 @@ public partial class ShellWindow : IShellView
public ShellWindow()
{
InitializeComponent();
showLogKeyBinding.Command = new DelegateCommand(ShowLog);
}

public double VirtualScreenLeft => SystemParameters.VirtualScreenLeft;
Expand All @@ -35,4 +38,16 @@ public bool IsMaximized
}
}
}

public static void ShowLog()
{
try
{
Process.Start(new ProcessStartInfo(App.LogFileName) { UseShellExecute = true });
}
catch (Exception exception)
{
Log.Default.Error(exception, "ShowLog");
}
}
}

0 comments on commit 48b0dec

Please sign in to comment.