diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 3038326ea5..e62be39f0e 100755 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Configuration; +using System.Reflection; using System.Threading; using System.Web; using LightInject; @@ -52,6 +53,9 @@ namespace Umbraco.Core.Runtime container.RegisterInstance(logger); // now it is ok to use Current.Logger + ConfigureUnhandledException(logger); + ConfigureAssemblyResolve(logger); + Compose(container); // prepare essential stuff @@ -125,6 +129,38 @@ namespace Umbraco.Core.Runtime return SerilogLogger.CreateWithDefaultConfiguration(); } + protected virtual void ConfigureUnhandledException(ILogger logger) + { + //take care of unhandled exceptions - there is nothing we can do to + // prevent the launch process to go down but at least we can try + // and log the exception + AppDomain.CurrentDomain.UnhandledException += (_, args) => + { + var exception = (Exception)args.ExceptionObject; + var isTerminating = args.IsTerminating; // always true? + + var msg = "Unhandled exception in AppDomain"; + if (isTerminating) msg += " (terminating)"; + msg += "."; + logger.Error(exception, msg); + }; + } + + protected virtual void ConfigureAssemblyResolve(ILogger logger) + { + // When an assembly can't be resolved. In here we can do magic with the assembly name and try loading another. + // This is used for loading a signed assembly of AutoMapper (v. 3.1+) without having to recompile old code. + AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => + { + // ensure the assembly is indeed AutoMapper and that the PublicKeyToken is null before trying to Load again + // do NOT just replace this with 'return Assembly', as it will cause an infinite loop -> stackoverflow + if (args.Name.StartsWith("AutoMapper") && args.Name.EndsWith("PublicKeyToken=null")) + return Assembly.Load(args.Name.Replace(", PublicKeyToken=null", ", PublicKeyToken=be96cd2c38ef1005")); + return null; + }; + } + + private void AquireMainDom(IServiceFactory container) { using (var timer = ProfilingLogger.DebugDuration("Acquiring MainDom.", "Aquired.")) diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index aa261ac55f..080002b18e 100755 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -58,42 +58,6 @@ namespace Umbraco.Web // get runtime & boot _runtime = GetRuntime(); _runtime.Boot(container); - - var logger = container.GetInstance(); - - ConfigureUnhandledException(logger); - ConfigureAssemblyResolve(logger); - } - - protected virtual void ConfigureUnhandledException(ILogger logger) - { - //take care of unhandled exceptions - there is nothing we can do to - // prevent the entire w3wp process to go down but at least we can try - // and log the exception - AppDomain.CurrentDomain.UnhandledException += (_, args) => - { - var exception = (Exception)args.ExceptionObject; - var isTerminating = args.IsTerminating; // always true? - - var msg = "Unhandled exception in AppDomain"; - if (isTerminating) msg += " (terminating)"; - msg += "."; - logger.Error(exception, msg); - }; - } - - protected virtual void ConfigureAssemblyResolve(ILogger logger) - { - // When an assembly can't be resolved. In here we can do magic with the assembly name and try loading another. - // This is used for loading a signed assembly of AutoMapper (v. 3.1+) without having to recompile old code. - AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => - { - // ensure the assembly is indeed AutoMapper and that the PublicKeyToken is null before trying to Load again - // do NOT just replace this with 'return Assembly', as it will cause an infinite loop -> stackoverflow - if (args.Name.StartsWith("AutoMapper") && args.Name.EndsWith("PublicKeyToken=null")) - return Assembly.Load(args.Name.Replace(", PublicKeyToken=null", ", PublicKeyToken=be96cd2c38ef1005")); - return null; - }; } // called by ASP.NET (auto event wireup) once per app domain