Skip to content

Instantly share code, notes, and snippets.

@AndrewNewcomb
Created April 6, 2013 08:27
Show Gist options
  • Save AndrewNewcomb/5325394 to your computer and use it in GitHub Desktop.
Save AndrewNewcomb/5325394 to your computer and use it in GitHub Desktop.
MiniProfilerTraceListener is a custom TraceListener that sends all messages to the StackExchange MiniProfiler.
using System.Diagnostics;
using StackExchange.Profiling;
namespace PSL.Web.Infrastructure
{
//Needs web.config entry
//<add name="TraceToMiniProfiler" type="PSL.Web.Infrastructure.MiniProfilerTraceListener, theassemblyname" initializeData="" />
public class MiniProfilerTraceListener : TraceListener
{
public override void Write(string message)
{
WriteToProfiler(message);
}
public override void WriteLine(string message)
{
WriteToProfiler(message);
}
private static void WriteToProfiler(string message)
{
MiniProfiler profiler = MiniProfiler.Current;
using (profiler.Step(message))
{
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment