Created
October 12, 2012 20:09
-
-
Save sihugh/3881238 to your computer and use it in GitHub Desktop.
Traces WebControl lifecycle to provide timings in the Asp.NET tracing output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.UI.Adapters; | |
namespace SH.ControlAdapters | |
{ | |
/// <summary> | |
/// When used with ASP.NET tracing provides a way of tracking performance of WebControls. | |
/// </summary> | |
public class TracingControlAdapter : ControlAdapter | |
{ | |
private const string TracingCategory = "sh.tracing.controlevents"; | |
protected override void CreateChildControls() | |
{ | |
const string method = "CreateChildControls"; | |
WriteTracePre(method); | |
base.CreateChildControls(); | |
WriteTracePost(method); | |
} | |
protected override void OnInit(EventArgs e) | |
{ | |
const string method = "OnInit"; | |
WriteTracePre(method); | |
base.OnInit(e); | |
WriteTracePost(method); | |
} | |
protected override void OnLoad(EventArgs e) | |
{ | |
const string method = "OnLoad"; | |
WriteTracePre(method); | |
base.OnLoad(e); | |
WriteTracePost(method); | |
} | |
protected override void Render(System.Web.UI.HtmlTextWriter writer) | |
{ | |
const string method = "Render"; | |
WriteTracePre(method); | |
base.Render(writer); | |
WriteTracePost(method); | |
} | |
private void WriteTracePre(string message) | |
{ | |
WriteTrace("Begin : " + message); | |
} | |
private void WriteTracePost(string message) | |
{ | |
WriteTrace("End : " + message); | |
} | |
private void WriteTrace(string message) | |
{ | |
Page.Trace.Write(TracingCategory, message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment