Log ASP.NET Web API (Service) Trace into Database

Topics: Exception Handling Application Block, Logging Application Block
Apr 5, 2013 at 11:31 PM
Hi there

Being built on top of ASP.NET framework Web API takes advantage of .Net.

would appreciate resources to write Web API Traces into Database using Logging application block.

I strongly believe that above is feasible through configuration in Web.config rather than any code to be written in the Web API Service.

Logging WCF exceptions was achieved, please refer https://entlib.codeplex.com/discussions/361057
Apr 9, 2013 at 4:47 AM
Edited May 1, 2013 at 9:27 PM
You can route ASP.NET tracing to System.Diagnostic tracing using the following configuration:
<system.web>
      <trace writeToDiagnosticsTrace="true"/>
</system.web>
Then you can use the EntLibLoggingProxyTraceListener to write to the configured Enterprise Library destinations. To do this via config use:
<system.diagnostics>
  <trace autoflush="true">
    <listeners>
      <add name="EntLib"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EntLibLoggingProxyTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </listeners>
  </trace>
</system.diagnostics>
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Apr 9, 2013 at 11:18 AM
Thank you Randy.

I think that rest all are same as for WCF configuration? https://entlib.codeplex.com/discussions/361057