Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Web Service Logging

My ideal situation for logging in our web service would be to log all the method calls (authentication as well as data access) with the parameters passed to them as well as errors that may have occured, and have them linked with a single ID that associates them with the same call. In addition, I'd ideally like to be able to control whether all parameters are logged, or if just the method call is logged. I'd like to be able to control if all logins are logged or just the failed ones. Again, all information retrieved in a single request would be linked together via an id (guid or otherwise).

This is my ideal logging situation. If anyone knows how to implement all of this and would be willing to move to the Manchester, NH area... ;)

But seriously, does anyone know how I would go about tying a webservice request received to an error, or method call? My initial attempts involve messing around in a Soap Extension, trying to add a header (soap or html) and what not to pass an arbitrary value from the extension into the service itself. All my attempts have not succeeded.

Our current logging situation has the authentication logging to one table, the method/business calls to another table, and exceptions logging to another table, with no interconnection between them. Timestamps are helpful, sometimes, but not reliable enough to effectively debug. We're currently on .Net 2.0 with the potential to be using 3.5 by the end of the year, so it would be more helpful if replies were kept to 2.0 functionality.

Anyone got any ideas?

like image 478
Wes P Avatar asked Sep 26 '08 20:09

Wes P


1 Answers

Use wcf if possible and implement message logging see http://msdn.microsoft.com/en-us/library/ms730064.aspx

<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>

<system.serviceModel>
  <diagnostics>
    <messageLogging 
         logEntireMessage="true" 
         logMalformedMessages="false"
         logMessagesAtServiceLevel="true" 
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
</system.serviceModel>
like image 51
Claus Thomsen Avatar answered Sep 21 '22 06:09

Claus Thomsen