Skip to content

Commit c254552

Browse files
author
Kajetan Jonak
committed
Unhandled exceptions are logged to log.txt
1 parent 16b6a3c commit c254552

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Okoń_GUI/App.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using System.Windows;
1111
using GUI_v2.View;
1212
using GUI_v2.ViewModel;
13+
14+
1315
namespace Okoń_GUI
1416
{
1517
/// <summary>
@@ -19,13 +21,19 @@ public partial class App : Application
1921
{
2022
private ModelContainer modelContainer;
2123

24+
private void toFile(string msg)
25+
{
26+
System.IO.File.AppendAllText("log.txt", msg);
27+
}
2228
protected override void OnStartup(StartupEventArgs e)
2329
{
30+
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
2431
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
2532
base.OnStartup(e);
2633
LoadingWindow loadingWindow = new LoadingWindow();
2734
loadingWindow.Show();
2835
ModelLoader loader = new ModelLoader(loadingWindow);
36+
2937
Task.Factory.StartNew(() =>
3038
{
3139
loader.LoadUserSettings();
@@ -46,6 +54,12 @@ protected override void OnStartup(StartupEventArgs e)
4654

4755
}
4856

57+
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
58+
{
59+
toFile(e.ExceptionObject.ToString());
60+
61+
}
62+
4963
private void Application_Exit(object sender, ExitEventArgs e)
5064
{
5165
modelContainer.keyboardController.StopController();

Okoń_GUI/Okoń_GUI.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@
9191
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
9292
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.19\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
9393
</Reference>
94+
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
95+
<HintPath>..\packages\NLog.4.7.6\lib\net45\NLog.dll</HintPath>
96+
</Reference>
9497
<Reference Include="System" />
98+
<Reference Include="System.Configuration" />
9599
<Reference Include="System.Data" />
100+
<Reference Include="System.IO.Compression" />
101+
<Reference Include="System.Runtime.Serialization" />
102+
<Reference Include="System.ServiceModel" />
103+
<Reference Include="System.Transactions" />
96104
<Reference Include="System.Xml" />
97105
<Reference Include="Microsoft.CSharp" />
98106
<Reference Include="System.Core" />

Okoń_GUI/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.19" targetFramework="net472" />
4+
<package id="NLog" version="4.7.6" targetFramework="net472" />
45
</packages>

0 commit comments

Comments
 (0)