diff --git a/src/Umbraco.Core/Profiling/WebProfiler.cs b/src/Umbraco.Core/Profiling/WebProfiler.cs
index 56918ff349..3a1974279e 100644
--- a/src/Umbraco.Core/Profiling/WebProfiler.cs
+++ b/src/Umbraco.Core/Profiling/WebProfiler.cs
@@ -1,6 +1,7 @@
using System;
using System.Web;
using StackExchange.Profiling;
+using StackExchange.Profiling.SqlFormatters;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
@@ -52,13 +53,8 @@ namespace Umbraco.Core.Profiling
///
void UmbracoApplicationEndRequest(object sender, EventArgs e)
{
- if (GlobalSettings.DebugMode == false) return;
- var request = TryGetRequest(sender);
- if (request.Success == false) return;
- if (request.Result.Url.IsClientSideRequest()) return;
- if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false)
+ if (CanPerformProfilingAction(sender))
{
- //stop the profiler
Stop();
}
}
@@ -70,17 +66,28 @@ namespace Umbraco.Core.Profiling
///
void UmbracoApplicationBeginRequest(object sender, EventArgs e)
{
- if (GlobalSettings.DebugMode == false) return;
- var request = TryGetRequest(sender);
- if (request.Success == false) return;
- if (request.Result.Url.IsClientSideRequest()) return;
- if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false)
+ if (CanPerformProfilingAction(sender))
{
- //start the profiler
Start();
}
}
+ private bool CanPerformProfilingAction(object sender)
+ {
+ if (GlobalSettings.DebugMode == false)
+ return false;
+
+ //will not run in medium trust
+ if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High)
+ return false;
+
+ var request = TryGetRequest(sender);
+ if (request.Success == false || request.Result.Url.IsClientSideRequest() || string.IsNullOrEmpty(request.Result["umbDebug"]))
+ return false;
+
+ return true;
+ }
+
///
/// Render the UI to display the profiler
///
@@ -103,9 +110,7 @@ namespace Umbraco.Core.Profiling
///
public IDisposable Step(string name)
{
- if (GlobalSettings.DebugMode == false) return null;
-
- return MiniProfiler.Current.Step(name);
+ return GlobalSettings.DebugMode == false ? null : MiniProfiler.Current.Step(name);
}
///
@@ -113,10 +118,8 @@ namespace Umbraco.Core.Profiling
///
public void Start()
{
- if (GlobalSettings.DebugMode == false) return;
- //will not run in medium trust
- if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return;
-
+ MiniProfiler.Settings.SqlFormatter = new SqlServerFormatter();
+ MiniProfiler.Settings.StackMaxLength = 5000;
MiniProfiler.Start();
}
@@ -129,10 +132,6 @@ namespace Umbraco.Core.Profiling
///
public void Stop(bool discardResults = false)
{
- if (GlobalSettings.DebugMode == false) return;
- //will not run in medium trust
- if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return;
-
MiniProfiler.Stop(discardResults);
}
@@ -156,6 +155,5 @@ namespace Umbraco.Core.Profiling
return new Attempt(ex);
}
}
-
}
}
\ No newline at end of file