From 5ed94065a71fb438ddeda5b431cb1d6153d20da8 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 24 Sep 2020 18:45:26 +1000 Subject: [PATCH] Fixes issue with exceptions in logs because we are trying to unbind from httpapplication events but you cannot do that. --- .../Logging/WebProfilerComponent.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web/Logging/WebProfilerComponent.cs b/src/Umbraco.Web/Logging/WebProfilerComponent.cs index 1cb2142199..ff25eb6a22 100755 --- a/src/Umbraco.Web/Logging/WebProfilerComponent.cs +++ b/src/Umbraco.Web/Logging/WebProfilerComponent.cs @@ -10,7 +10,6 @@ namespace Umbraco.Web.Logging { private readonly WebProfiler _profiler; private readonly bool _profile; - private readonly List _terminate = new List(); public WebProfilerComponent(IProfiler profiler, ILogger logger) { @@ -39,21 +38,20 @@ namespace Umbraco.Web.Logging public void Terminate() { UmbracoApplicationBase.ApplicationInit -= InitializeApplication; - foreach (var t in _terminate) t(); } private void InitializeApplication(object sender, EventArgs args) { if (!(sender is HttpApplication app)) return; - // for *each* application (this will run more than once) - void beginRequest(object s, EventArgs a) => _profiler.UmbracoApplicationBeginRequest(s, a); - app.BeginRequest += beginRequest; - _terminate.Add(() => app.BeginRequest -= beginRequest); - - void endRequest(object s, EventArgs a) => _profiler.UmbracoApplicationEndRequest(s, a); - app.EndRequest += endRequest; - _terminate.Add(() => app.EndRequest -= endRequest); + // NOTE: We do not unbind these events ... because you just can't do that for HttpApplication events, they will + // be removed when the app dies. + app.BeginRequest += BeginRequest; + app.EndRequest += EndRequest; } + + private void BeginRequest(object s, EventArgs a) => _profiler.UmbracoApplicationBeginRequest(s, a); + + private void EndRequest(object s, EventArgs a) => _profiler.UmbracoApplicationEndRequest(s, a); } }