NLog not working in WCF service

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

NLog not working in WCF service

StrandedPirate
Posting this for future reference and it should help others. In my project NLog was logging just fine in my ASP.Net application but would never log anything from a WCF service. After reading tons of threads I found that the below configuration would generate a log file that finally let me pinpoint the reason why my logging wasn't working in the WCF service. Turned out a column in the database that NLog was logging to was too short and SQL Server was throwing a "data would be truncted" error. Would have never figured this out unless the internal log file was generated so if your in the same boat setup your config file like below and at the bottom of it you'll see some exceptions that will help you. One thing to note, my WCF service was setup in the web.config with aspNetCompatibilityEnabled="true" which is necessary if your logging asp.net server variables in WCF services and also the internalLogFile needed to have a full path not a relative one.

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Trace"
      internalLogFile="d:\nlog_log.log"
      throwExceptions="true">
....
</nlog>