ASP.NET Web API logging with TextWriterTraceListener…
Update Web.config
to this form:
<appSettings>
<add key="defaultTraceSourceName" value="my-source" />
</appSettings>
<system.diagnostics>
<sources>
<source name="my-source">
<listeners>
<add name="fileLogListener" />
<remove name="Default" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="fileLogListener"
initializeData="\\MyServer\logFiles\My.log"
type="System.Diagnostics.TextWriterTraceListener"
/>
</sharedListeners>
</system.diagnostics>
Install NuGet package Microsoft.AspNet.WebApi.Tracing
.
Add this line to WebApiConfig.Register()
:
config.EnableSystemDiagnosticsTracing();
Also the information in “Compiling Conditionally with Trace and Debug” may apply.