Skip Navigation Links

Configuring a TraceSource

Categories

A common pattern in log4net is to create an instance of a logger in a class, passing in the name of the class. This logger can then be setup via config files and violin, you've got tracing that you can turn on and off at the class level. Rather handy.

TraceSource allows exactly the same thing. Simply pass a name into the constructor and define the parameters in the app.config. But the common idiom is to not build a TraceSource per class, but group them at a more logical (as in "not-physical", rather than Vulcan) level, usually named after a namespace, but sometimes also a class or other logical identifier. This gives you finer control of the logging of an entire feature set.

Why am I telling you this?

Because generally, the .net framework doesn't have much logging of what it's doing. .net 3 has tons, and it's all done through TraceSources. This page on msdn details how to turn on tracing for WCF. Here are the TraceSources defined:

  • System.ServiceModel: Logs all stages of WCF processing, whenever configuration is read, a message is processed in transport, security processing, a message is dispatched in user code, etc.
  • System.ServiceModel.MessageLogging: Logs all messages that flow through the system.
  • System.IdentityModel
  • System.ServiceModel.Activation
  • System.IO.Log: Logging for the .NET Framework interface to the Common Log File System (CLFS).
  • System.Runtime.Serialization: Logs when objects are read or written.
  • CardSpace

Quite a few sources. But looking at the recommended tracing levels, or using the Service Configuration Editor, you might be surprised to see more than just "System.ServiceModel" or "System.ServiceModel.MessageLogging". I'm certainly regretting not finding the "CardSpace" source sooner.

WPF gets in on the act too, with it's own set of TraceSources:

  • System.Windows.Media.Animation
  • System.Windows.Data: Databinding
  • System.Windows.DependencyProperty: Tracing for the dependency property system
  • System.Windows.Documents
  • System.Windows.Freezable: Tracing for objects that have been made immutable
  • System.Windows.Markup: All about XAML
  • System.Windows.NameScope: Tracing naming and the scopes used for name lookup and collisions
  • System.Windows.ResourceDictionary
  • System.Windows.RoutedEvent

The odd thing about WPF logging is that not only do you have to configure it in your app.config, you also need to enable a registry key. I don't know why the config isn't enough, I guess it's to do with performance.

posted 7/27/2007 10:50:51 AM

 

Comments:

There are no comments to display for this post.

 

Name:  
Url (optional):  
Subject:  
Comment:  

Enter Captcha Validation:
(If you cannot read the Captcha image, press "Reset Image" to generate a new one)