Created
April 3, 2013 09:57
-
-
Save dohaivu/5299910 to your computer and use it in GitHub Desktop.
tracing for webapi
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
public static void Register(HttpConfiguration config) | |
{ | |
config.Services.Replace(typeof(ITraceWriter), new MyTracer()); | |
} | |
public class MyTracer : ITraceWriter | |
{ | |
public void Trace(HttpRequestMessage request, string category, TraceLevel level, | |
Action<TraceRecord> traceAction) | |
{ | |
TraceRecord rec = new TraceRecord(request, category, level); | |
traceAction(rec); | |
WriteTrace(rec); | |
} | |
protected void WriteTrace(TraceRecord rec) | |
{ | |
var message = string.Format("{0};{1};{2}", | |
rec.Operator, rec.Operation, rec.Message); | |
System.Diagnostics.Trace.WriteLine(message, rec.Category); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment