Files
Umbraco-CMS/src/Umbraco.Web/Logging/WebProfilerComponent.cs

52 lines
2.0 KiB
C#
Raw Normal View History

2016-09-08 18:43:58 +02:00
using System;
using System.Web;
using Umbraco.Core;
2016-09-08 18:43:58 +02:00
using Umbraco.Core.Components;
using Umbraco.Core.Logging;
2016-09-08 18:43:58 +02:00
namespace Umbraco.Web.Logging
2016-09-08 18:43:58 +02:00
{
2019-01-03 21:00:28 +01:00
internal class WebProfilerComponent : IComponent
2016-09-08 18:43:58 +02:00
{
// the profiler is too important to be composed in a component,
// it is composed first thing in WebRuntime.Compose - this component
// only initializes it if needed.
//
//public override void Compose(Composition Composition)
2016-09-08 18:43:58 +02:00
//{
// composition.Container.RegisterSingleton<IProfiler, WebProfiler>();
2016-09-08 18:43:58 +02:00
//}
private WebProfiler _profiler;
2019-01-03 21:00:28 +01:00
public WebProfilerComponent(IProfiler profiler, ILogger logger, IRuntimeState runtime)
2016-09-08 18:43:58 +02:00
{
2017-07-20 11:21:28 +02:00
// although registered in WebRuntime.Compose, ensure that we have not
// been replaced by another component, and we are still "the" profiler
2016-09-08 18:43:58 +02:00
_profiler = profiler as WebProfiler;
if (_profiler == null)
2016-09-08 18:43:58 +02:00
{
// if VoidProfiler was registered, let it be known
var vp = profiler as VoidProfiler;
if (vp != null)
logger.Info<WebProfilerComponent>("Profiler is VoidProfiler, not profiling (must run debug mode to profile).");
return;
2016-09-08 18:43:58 +02:00
}
// bind to ApplicationInit - ie execute the application initialization for *each* application
// it would be a mistake to try and bind to the current application events
UmbracoApplicationBase.ApplicationInit += InitializeApplication;
2016-09-08 18:43:58 +02:00
}
private void InitializeApplication(object sender, EventArgs args)
{
var app = sender as HttpApplication;
if (app == null) return;
// for *each* application (this will run more than once)
app.BeginRequest += (s, a) => _profiler.UmbracoApplicationBeginRequest(s, a);
app.EndRequest += (s, a) => _profiler.UmbracoApplicationEndRequest(s, a);
}
}
2017-07-20 11:21:28 +02:00
}