-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented rudimentary crash log dumping.
- Loading branch information
1 parent
517aefe
commit e57ecef
Showing
8 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using NLog; | ||
using System.Windows; | ||
|
||
namespace PostScriptumMortarCalculator.Bootstrapper | ||
{ | ||
public class ErrorLogger | ||
{ | ||
private static readonly Logger m_logger = LogManager.GetCurrentClassLogger(); | ||
public ErrorLogger() | ||
{ | ||
AppDomain.CurrentDomain.UnhandledException += (s, e) => | ||
LogUnhandledException((Exception)e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException"); | ||
|
||
Application.Current.DispatcherUnhandledException += (s, e) => | ||
{ | ||
LogUnhandledException(e.Exception, "Application.Current.DispatcherUnhandledException"); | ||
e.Handled = true; | ||
}; | ||
|
||
TaskScheduler.UnobservedTaskException += (s, e) => | ||
{ | ||
LogUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException"); | ||
e.SetObserved(); | ||
}; | ||
} | ||
|
||
private void LogUnhandledException(Exception exception, string source) | ||
{ | ||
var message = $"Unhandled exception ({source})"; | ||
try | ||
{ | ||
var assemblyName = Assembly.GetExecutingAssembly().GetName(); | ||
message = $"Unhandled exception in {assemblyName.Name} v{assemblyName.Version}"; | ||
} | ||
catch (Exception ex) | ||
{ | ||
m_logger.Trace(ex, "Exception in LogUnhandledException"); | ||
LogManager.Shutdown(); | ||
Application.Current.Shutdown(); | ||
} | ||
finally | ||
{ | ||
m_logger.Trace(exception, message); | ||
LogManager.Shutdown(); | ||
Application.Current.Shutdown(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#if (!DEBUG) | ||
using System.Reflection; | ||
#endif | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters