What does the <messageLogging> tag do within <system.diagnostics><diagnostics> and is it bad to include in Production WCF system?
In a production web.config file for a WCF service I see the configuration included below and am wondering what the impact of the <messageLogging> tag is, if any? Based on Recommended Settings for Tracing and Message Logging that tag shouldn't be there, but I'd like to know what the impact is. I'd prefer to leave it if possible (this is installed at a number of sites so it will be a pain to update), provided it's not having a significant performance impact.
<system.serviceModel> ... (lots more stuff) ... <diagnostics wmiProviderEnabled="true"> <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" /> </diagnostics> </system.serviceModel> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="ServiceTrace.svclog" /> </sharedListeners> </system.diagnostics>
As with most diagnostics questions the answer is "It Depends".
What does it do: The tag sets up what should be logged if a listener finds a message and decides to log it. If you had only the diagnostics\messageLogging tags setup without any kind of "sources" setup then it would do absolutely nothing. (Here is what each of those settings means: http://msdn.microsoft.com/en-us/library/ms731308.aspx)
In your code example you do have a source. The source is from System.ServiceModel and the switchValue is set to listen for only Warning messages. You also have a xmlwritertracelistener under sharedlistener which is basically an xml log writer. The initializeData value is what this xml log file is named. Look in your applications root directory and you should see a filed named ServiceTrace.svclog.
So basically your application is only logging WCF messages at a warning level, logging the full message, and only keeping 3000 of those logs.
Bad to include in production? This depends. If your application is hit millions of times an hour, needs every ounce of speed, and every cycle of a CPU I would remove it. If not, then I would keep it in. Based on timing's I've seen and others have reported ( http://stackoverflow.com/a/2323411/44336 ) the performance impact of having "warning" set is negligible. If you turned on debug/information/activitytracing that is another story and will degrade performance.
If you do have a bug or your service becomes unstable those logs might be beneficial.
If you are running this in production now, look at the ServiceTrace.svclog file and see how many entries are in there. If you are logging many a second then I'd turn it off (or fix the warnings). You can use SvcTraceViewer.exe to view the actual trace.