Log also unhandled exceptions

This commit is contained in:
JustArchi
2016-01-09 19:54:08 +01:00
parent 6a12a26612
commit daf4efa054
2 changed files with 16 additions and 0 deletions

View File

@@ -62,6 +62,12 @@ namespace ArchiSteamFarm {
internal static void LogGenericException(string botName, Exception exception, [CallerMemberName] string previousMethodName = "") {
Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message);
Log("[!] StackTrace: " + exception.StackTrace);
Exception innerException = exception.InnerException;
if (innerException != null) {
LogGenericException(botName, innerException, previousMethodName);
}
}
internal static void LogGenericWarning(string botName, string message, [CallerMemberName] string previousMethodName = "") {

View File

@@ -204,7 +204,17 @@ namespace ArchiSteamFarm {
}
}
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
if (sender == null || args == null) {
return;
}
Logging.LogGenericException("Main", (Exception) args.ExceptionObject);
}
private static void Main(string[] args) {
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version);
Directory.SetCurrentDirectory(ExecutableDirectory);
InitServices();