diff --git a/src/neo/NeoSystem.cs b/src/neo/NeoSystem.cs index aa18723e01..d666a5d1a0 100644 --- a/src/neo/NeoSystem.cs +++ b/src/neo/NeoSystem.cs @@ -26,6 +26,12 @@ public class NeoSystem : IDisposable private ChannelsConfig start_message = null; private bool suspend = false; + static NeoSystem() + { + // Unify unhandled exceptions + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + } + public NeoSystem(string storageEngine = null) { Plugin.LoadPlugins(this); @@ -39,6 +45,11 @@ public NeoSystem(string storageEngine = null) plugin.OnPluginsLoaded(); } + private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Utility.Log("UnhandledException", LogLevel.Fatal, e.ExceptionObject); + } + public void Dispose() { foreach (var p in Plugin.Plugins) diff --git a/src/neo/Plugins/ILogPlugin.cs b/src/neo/Plugins/ILogPlugin.cs index c0733f9143..0934cc414a 100644 --- a/src/neo/Plugins/ILogPlugin.cs +++ b/src/neo/Plugins/ILogPlugin.cs @@ -2,6 +2,6 @@ namespace Neo.Plugins { public interface ILogPlugin { - void Log(string source, LogLevel level, string message); + void Log(string source, LogLevel level, object message); } } diff --git a/src/neo/Plugins/Plugin.cs b/src/neo/Plugins/Plugin.cs index b8d775b95c..26c0befe3e 100644 --- a/src/neo/Plugins/Plugin.cs +++ b/src/neo/Plugins/Plugin.cs @@ -109,7 +109,7 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven } catch (Exception ex) { - Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to resolve assembly or its dependency: {ex.Message}"); + Utility.Log(nameof(Plugin), LogLevel.Error, ex); return null; } } @@ -137,7 +137,7 @@ private static void LoadPlugin(Assembly assembly) } catch (Exception ex) { - Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to initialize plugin: {ex.Message}"); + Utility.Log(nameof(Plugin), LogLevel.Error, ex); } } } @@ -161,7 +161,7 @@ internal static void LoadPlugins(NeoSystem system) } } - protected void Log(string message, LogLevel level = LogLevel.Info) + protected void Log(object message, LogLevel level = LogLevel.Info) { Utility.Log($"{nameof(Plugin)}:{Name}", level, message); } diff --git a/src/neo/Utility.cs b/src/neo/Utility.cs index c5145ad760..c56629f567 100644 --- a/src/neo/Utility.cs +++ b/src/neo/Utility.cs @@ -13,7 +13,7 @@ internal class Logger : ReceiveActor public Logger() { Receive(_ => Sender.Tell(new LoggerInitialized())); - Receive(e => Log(e.LogSource, (LogLevel)e.LogLevel(), e.Message.ToString())); + Receive(e => Log(e.LogSource, (LogLevel)e.LogLevel(), e.Message)); } } @@ -31,7 +31,7 @@ public static IConfigurationRoot LoadConfig(string config) .Build(); } - public static void Log(string source, LogLevel level, string message) + public static void Log(string source, LogLevel level, object message) { foreach (ILogPlugin plugin in Plugin.Loggers) plugin.Log(source, level, message); diff --git a/tests/neo.UnitTests/Plugins/TestLogPlugin.cs b/tests/neo.UnitTests/Plugins/TestLogPlugin.cs index 215715d236..90d9d2c4df 100644 --- a/tests/neo.UnitTests/Plugins/TestLogPlugin.cs +++ b/tests/neo.UnitTests/Plugins/TestLogPlugin.cs @@ -11,7 +11,7 @@ public TestLogPlugin() : base() { } protected override void Configure() { } - void ILogPlugin.Log(string source, LogLevel level, string message) + void ILogPlugin.Log(string source, LogLevel level, object message) { Output = source + "_" + level.ToString() + "_" + message; }