Exception information logging
This commit is contained in:
50
Eve-O-Preview/ApplicationBase/ExceptionHandler.cs
Normal file
50
Eve-O-Preview/ApplicationBase/ExceptionHandler.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace EveOPreview
|
||||||
|
{
|
||||||
|
// A really very primitive exception handler stuff here
|
||||||
|
// No IoC, no fancy DI containers - just a plain exception stacktrace dump
|
||||||
|
// If this code is called then something was gone really bad
|
||||||
|
// so even the DI infrastructure might be dead already.
|
||||||
|
// So this dumb and non elegant approach is used
|
||||||
|
sealed class ExceptionHandler
|
||||||
|
{
|
||||||
|
private const string ExceptionDumpFileName = "EVE-O Preview.log";
|
||||||
|
private const string ExceptionMessage = "EVE-O Preview has encountered a problem and needs to close. Additional information has been saved in the crash log file.";
|
||||||
|
|
||||||
|
public void SetupExceptionHandlers()
|
||||||
|
{
|
||||||
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||||
|
Application.ThreadException += delegate (Object sender, ThreadExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
this.ExceptionEventHandler(e.Exception);
|
||||||
|
};
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += delegate (Object sender, UnhandledExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
this.ExceptionEventHandler(e.ExceptionObject as Exception);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExceptionEventHandler(Exception exception)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String exceptionMessage = exception.ToString();
|
||||||
|
File.WriteAllText(ExceptionHandler.ExceptionDumpFileName, exceptionMessage);
|
||||||
|
|
||||||
|
MessageBox.Show(ExceptionHandler.ExceptionMessage, @"EVE-O Preview", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// We are in unstable state now so even this operation might fail
|
||||||
|
// Still we actually don't care anymore - anyway the application has been cashed
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -88,6 +88,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ApplicationBase\ApplicationController.cs" />
|
<Compile Include="ApplicationBase\ApplicationController.cs" />
|
||||||
|
<Compile Include="ApplicationBase\ExceptionHandler.cs" />
|
||||||
<Compile Include="ApplicationBase\IApplicationController.cs" />
|
<Compile Include="ApplicationBase\IApplicationController.cs" />
|
||||||
<Compile Include="ApplicationBase\IIocContainer.cs" />
|
<Compile Include="ApplicationBase\IIocContainer.cs" />
|
||||||
<Compile Include="ApplicationBase\IPresenterGeneric.cs" />
|
<Compile Include="ApplicationBase\IPresenterGeneric.cs" />
|
||||||
|
@@ -27,15 +27,15 @@ namespace EveOPreview
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExceptionHandler handler = new ExceptionHandler();
|
||||||
|
handler.SetupExceptionHandlers();
|
||||||
|
|
||||||
Program.InitializeWinFormsGui();
|
Program.InitializeWinFormsGui();
|
||||||
|
|
||||||
IApplicationController controller = Program.InitializeApplicationController();
|
IApplicationController controller = Program.InitializeApplicationController();
|
||||||
|
|
||||||
Program.SetupApplicationConttroller(controller, Program.GetCustomConfigFile(args));
|
Program.SetupApplicationConttroller(controller, Program.GetCustomConfigFile(args));
|
||||||
|
|
||||||
controller.Run<MainPresenter>();
|
controller.Run<MainPresenter>();
|
||||||
|
|
||||||
token = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCustomConfigFile(string[] args)
|
private static string GetCustomConfigFile(string[] args)
|
||||||
|
Reference in New Issue
Block a user