We've been moving towards using ETW rather than the System.Diagnostics tracing in some of our BizTalk applications because a) you can enable / disable tracing without needing to restart the application and b) performance is a lot better (you can capture millions of events per second without killing your server vs thousands of events per second with System.Diagnostics).
I've not tried to implement it in a regular .NET application but there appear to be some blogs out there from people who have done it in .NET. http://blogs.msdn.com/b/sergeim/archive/2008/12/10/how-to-do-etw-logging-from-net-application.aspx http://naveensrinivasan.com/2010/03/17/using-clr-4-0-event-tracing-for-windows-etw-along-with-application-etw/ The link below is BizTalk specific but it shows the difference in perf between the major options (System.Diagnostics, EntLib, Log4Net, ETW): http://blogs.msdn.com/b/asgisv/archive/2010/05/11/best-practices-for-instrumenting-high-performance-biztalk-solutions.aspx I'm guessing it would be possible to build a generic ETW tracing framework that hooks into some of the WCF extensibility points without too many dramas (similar to how the BizTalk guys have done it). ________________________________ From: [email protected] [[email protected]] On Behalf Of Matt Siebert [[email protected]] Sent: Wednesday, 9 March 2011 9:40 AM To: ozDotNet Subject: Re: WCF TraceListeners I'd be really interested if there's a way to do this without the config file. I've already used these traces to fix an issue in development, and it'd be nice to be able to easily enable / disable this stuff out in the wild. I'm not totally familiar with the tracing system, but I've been working with TraceListeners lately thanks to Enterprise Library's Logging Application Block... The only way I can see to do this in code is to use reflection to get to the static DiagnosticTrace property on System.ServiceModel.DiagnosticUtility. The DiagnosticTrace type has a TraceSource property which looks like it'll allow you to configure the "System.ServiceModel" source, but I'm not sure if DiagnosticTrace will be created if there's nothing in the config file. It always frustrates me to see things that can only be configured by the config file, or when you can only ever find info on using the config files and nothing for configuring stuff in code. I'm often coding for scenarios where I wouldn't want a user to change certain settings (i.e. WCF) so I have to do things in code and I'll generally provide a custom config section just for the things I'm will to expose. That said, aside from a potential performance hit, tracing shouldn't really affect the app's functionality so I wouldn't be too concerned if it had to be exposed in the config file (although it is rather frustrating). If there is nothing in System.Configuration to help achieve this, then you could just code something to update the file as plain old XML (again, frustrating). Obviously, you'd still have to worry about permissions / elevation for writing to the file and restarting your app to use the new settings, or maybe TraceSource.Refresh() will work... On Tue, Mar 8, 2011 at 7:08 PM, Peter Maddin <[email protected]<mailto:[email protected]>> wrote: I can set up my wcf client proxy class in code. I can set up a Trace Listener in particular I would like to use the default XmlWriterTraceListener. There does not seem to be any way of intregrating a wcf client proxy with a trace listener short of building a custom tracelistener and integrating this via the app.config file. The very thing I am trying to avoid. I am not sure why it needs to be this difficult or hard. There must be a way of doing this so that this incredibly useful diagnostic tool can be used in a production environment at a client’s site. At http://msdn.microsoft.com/en-us/library/ms733025.aspx It states Windows Communication Foundation (WCF) outputs the following data for diagnostic tracing: • Traces for process milestones across all components of the applications, such as operation calls, code exceptions, warnings and other significant processing events. • Windows error events when the tracing feature malfunctions. See Event Logging<http://msdn.microsoft.com/en-us/library/ms733738.aspx>. WCF tracing is built on top of System.Diagnostics<http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx>. To use tracing, you should define trace sources in the configuration file or in code. WCF defines a trace source for each WCF assembly. The System.ServiceModel trace source is the most general WCF trace source, and records processing milestones across the WCF communication stack, from entering/leaving transport to entering/leaving user code. The System.ServiceModel.MessageLogging trace source records all messages that flow through the system. Well it says “or in code”, but how to do this in code is as elusive as ever. Regards Peter Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 6396 4285 Mobile: 0414 240 307 E-Mail : [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]> The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately.
