Saturday, May 31, 2014

Logging in WCF

Have you ever wondered how to log messages sent to a WCF service? I had an iPhone app not being able to connect to a method in a WCF service, so I did this to enable logging of requests:

  <diagnostics>
    <messageLogging
         logEntireMessage="true"
         logMalformedMessages="true"
         logMessagesAtServiceLevel="true"
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
  </system.serviceModel>
<system.diagnostics>
  <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\logs\messages.svclog" />
          </listeners>
      </source>
    </sources>

</system.diagnostics>

Then once you have a log file, open it with SvcTraceViewer.exe, the Service Trace Viewer tool from Microsoft.

Saturday, May 17, 2014

Socket.io: Sending logs to a file

It's quite simple to send the console messages from socket.io to a file. I followed this tutorial (http://masashi-k.blogspot.mx/2013/02/logger-for-socketio-save-it-into-redis.html) and the steps are:

1) Install winston
2) Configure the logger output file
3) Link the logger to socket.io using this code:


 var io = require('socket.io').listen(server, {
      logger : logger
    });