WCF Logging with parameters and method name - wcf

Im trying to keep a log of all the calls to my WCF Restfull service.
I need to be able to view method name, all the parameters that is passed to it, and any response (string, object, list)
Here is my set up in config file:
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="false"
logMessagesAtTransportLevel="true"
maxMessagesToLog="2147483647"
maxSizeOfMessageToLog="2147483647"/>
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing" propagateActivity="true">
<listeners>
<add name="ServiceModelTraceListener">
<filter type=""/>
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="ServiceModelMessageLoggingListener">
<filter type=""/>
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\Temp\Tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type=""/>
</add>
<add initializeData="c:\Temp\Messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type=""/>
</add>
</sharedListeners>
<trace autoflush="true"/>
In the Messages.svclog file, Activity tab doesn't show calls to my Method . It only shows passed parameters in the body of Received message. Response message doesnt show Method name either, but I can see it under Action property.
In the Tracelog.svclog file, Activity tab does show calls to my Method, but it doesn't show any parameters that are passed or response object
How can I set it up to see my methods being called with parameters and its response?

You will need to extend WCF to inject your logging into it. You can provide your own IOperationInvoker which can log inputs and outputs from the call or you can use IParameterInspector. You can also take a look at The Enterprise Services Logbook from IDesign (you have to search for it on the page) or here is direct link.

Related

Logging Request and Response values for a WCF request in client

I am trying to log the request ad response messages in my client while the client is consuming a thirdparty WebService.
Despite of many attempts the log file - MessageLog.svclog never gets created using the following WCF configuration in the app.config file. Please help.
<system.diagnostics>
<sources>
<source
name="System.ServiceModel.MessageLogging"
switchValue="Information, ActivityTracing" >
<listeners>
<add name="yourTrace"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\Log\MessageLog.svclog">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logMessagesAtTransportLevel="true"
logMessagesAtServiceLevel="false"
logMalformedMessages="true"
logEntireMessage="true"
maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />
</diagnostics>
</system.serviceModel>
Thank you !
Try this. Notice the SharedListeners node
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging"
switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\Log\MessageLog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
...
</system.serviceModel>
I had problem with WS Client tracing where App.config and folder permissions were totally ok. The solution in my case was that I renamed it to .exe.config (was built to .dll.config of the WS client dll). So make sure:
That the name in the folder of the config file matches the assembly name
That when you run/debug it, the assembly that config file is for, is really used and not assembly for other location.
If it is built into .dll.config it is maybe ignored cause it should be .exe.config.
-m

WCF Service Log - create a new file when exceed a file size limit or create it for every day

My application is using WCF, And I am creating a service log file on server. It is working correctly, It is writing same svclog file and it is increasing in size.
What would I have to do to create a new svclog file when it reaches a fixed file size like I want it to be 50MB, or it creates a new svclog file for each day.
Currently, The source and listeners have been defined in the web.config file as follows:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\ServiceLogs\app_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
</sharedListeners>
</system.diagnostics>
How can I do this?
You should create a custom trace listener.
There is a perfect sample from MS for this ! This example can not fit exactly with your needs, but it is easy to understand and so to change.
More info here

Where do Azure wcf service Trace.WriteLine requests go?

I have looked at a lot of different Azure and Wcf service examples. I have configured a trace listener and much trace information is appearing in the associated log file; however, I don't see the results of my Trace.WriteLine requests. I do see my Trace.WriteLine requests in the Azure debugger output panel.. Where is the output of these requests persisted?
From my Web.config
<system.diagnostics>
<sources>
<source propagateActivity="false" name="System.ServiceModel"
switchValue="Verbose,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="AzureLocalStorage">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Information">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="AzureLocalStorage">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"
name="AzureLocalStorage">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
From my AzureLocalStorageTraceListener.cs
public class AzureLocalStorageTraceListener : XmlWriterTraceListener
{
public AzureLocalStorageTraceListener()
: base(Path.Combine(AzureLocalStorageTraceListener.GetLogDirectory().Path, "WCFServiceWebRole1.svclog"))
{
}
public static DirectoryConfiguration GetLogDirectory()
{
DirectoryConfiguration directory = new DirectoryConfiguration();
directory.Container = "wad-tracefiles";
directory.DirectoryQuotaInMB = 10;
directory.Path = RoleEnvironment.GetLocalResource("WCFServiceWebRole1.svclog").RootPath;
return directory;
}
}
The AzureLocalStorageTraceListener you created simply logs to a *.svclog file. If you want to output logs to the emulator there are a few things you should take care of:
Add the DevelopmentFabricTraceListener to your shared listeners (this will also work for the 1.7 SDK)
<add type="Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener, Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Emulator">
<filter type="" />
</add>
Make sure the switch value is correct (you could try the value All to get started)
Change the logging level in the emulator (by right clicking the icon at the top right of the screen).

WCF: How do I trace message bodies?

I'm trying to diagnose a WCF service that is self-hosted in a relatively simple service host process (Service.exe).
I have Service.exe.config configured thus:
<?xml version="1.0" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\Service.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging maxMessagesToLog="1"
maxSizeOfMessageToLog="2147483647"
logEntireMessage="true"
logMessagesAtServiceLevel="true"
logMalformedMessages="true"
logMessagesAtTransportLevel="true">
</messageLogging>
</diagnostics>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
When I look at the resulting svclog file, I see many trace events being logged (I expected only the first message to be logged), and none of the messages being traced show a message body (only headers).
I'm sure I must be missing something simple here, but I don't see it.
UPDATE: When I look at the WCF Config Editor, there are two sections under "Diagnostics": MessageLogging and Tracing. When I click the "EnableMessageLogging" link, my config file gets updated:
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add initializeData="c:\temp\MessageBodyTracing.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="traceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\users\me\documents\visual studio 2010\projects\messagebodytracing\messagebodytracing\app_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
I guess the source named System.ServiceModel.MessageLogging is the key - I hadn't seen that in any documentation of message tracing...
Try to add:
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
in your diagnostics node, under messageLogging.
Set LogEntireMessage to true under Diagnostics->MessageLogging in the Service configuration Editor

Server-side tracing of SOAP messages for WCF service

I'm trying to follow this tutorial on configuring server-side SOAP tracing for my WCF service, as well as the MSDN documentation.
When I run a test, I see Activity 00000000 in Microsoft Service Trace Viewer but the messages tab is empty. C:\temp\Web_tracelog.svclog is being written but C:\temp\Web_messages.svclog is not.
I'm probably missing something simple here, but can't put my finger on it.
The Diagnostics tab of Microsoft Service Configuration Editor says everything is on. Relevant portions of web.config follow.
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing"
propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\temp\Web_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\temp\Web_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
</system.serviceModel>
Can't see what's wrong with that config, but here's the config I use that works without a problem if it's of any use:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener"
initializeData="c:\MyTracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
traceOutputOptions="Timestamp"/>
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
</system.serviceModel>