1

I created a webapi project and have used the following in the webconfig

<system.web>
  <compilation debug="true" targetFramework="4.5"/>
  <httpRuntime targetFramework="4.5" />
  <trace enabled="false" localOnly="true" pageOutput="false" writeToDiagnosticsTrace="false"></trace>
  <customErrors mode="On"/>
</system.web>

<system.diagnostics>
 <trace autoflush="true">
  <listeners>
  <add name="TestTracer" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Temp\Asptesttrace.log" />
  </listeners>
  </trace>
  <sources>
  <source name="Tracing" switchName="TraceSwitch">
   <listeners>
    <add name="TestTracer"></add>
   </listeners>
  </source>
 </sources>
 <switches>
  <add name="TraceSwitch" value="0"/>
 </switches>
</system.diagnostics>

My WebApiConfig.cs file has the config.EnableSystemDiagnosticsTracing(); to enable tracing

In my class file I am calling the Trace class as shown, to log the method

public void GetTipDetails()
{  
  System.Diagnostics.Trace.TraceInformation("Entering method - GetTipDetails");
}

Now, I want the user to enable or disable the trace using Webconfig. How do I do it?

AlexB
  • 7,302
  • 12
  • 56
  • 74

0 Answers0