I am attempting to enable WCF message tracing for a single service (one of several included in this IIS application). I have created a web.config file that is placed in the same physical directory as my .svc file. I am able to configure the service from this web.config file, modifying behaviors, endpoints etc. However, when I attempt to include the include a system.diagnostics node, it appears to have no effect. This does not produce a trace file:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="My.Awesome.Wcf.Service" />
<!-- my endpoints and behaviors are defined programmatically -->
</services>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000" />
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logs\Traces.svclog" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
</configuration>
If I move the entire system.diagnostics node out of this sub-directory web.config to the application’s root web.config, then it magically starts working. As far as I can tell, the system.diagnostics section is not limited to the application’s root web.config, since my machine.config shows this section definition:
<section name="system.diagnostics" type="System.Diagnostics.SystemDiagnosticsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Note that this definition does not include an “allowDefinition” attribute, which, according to this MSDN documentation for the section element means that it can be defined “Everywhere” which should include physical subdirectories. I have not been able to find any system.diagnostics definitions in any parent web.configs either.
Does anyone know why this system.diagnostics configuration might not be getting processed?
To close out this question: the real question is why would you want to specify WCF logging at a sub-folder level?
WCF hosting is at the IIS Application level. You can’t have WCF logging disabled for services at the root URL then enabled at lower levels. If you want to emulate such scenario, then you need 2 WCF applications, one within the other (in IIS); in .NET, they are 2 separate AppDomains.
If you prefer to stick to one AppDomain, then you can perhaps achieve what you are trying to accomplish to by creating message filters. See “Message Filters” in msdn.