This project has moved and is read-only. For the latest updates, please go here.

Reading attributes from config file

Nov 9, 2012 at 12:49 PM

Is it possible to read the attributes from app.config in constructor of the listener?

Nov 11, 2012 at 5:10 AM

If you look at the examples, e.g. for SqlDatabase in HelloLogging, then you will see you can add various attributes to a listener (in this case applicationName, commandText, etc).

There are also some standard attributes initializeData and traceOutputOptions.

If you look at the source code for SqlDatabaseTraceListener, you will see that the initializeData is passed into the constructor, so is available (it is mapped to a string or boolean depending on which constructor exists).

The other allowed attributes are based on the value of GetSupportAttributes, and the values are available in the dictionary Attributes, which is a property on the base class.

The .NET tracing infrastructure, which creates the listeners from the config, has to finish the constructor (create the object) before it can set the Attributes property, so I'm pretty sure the only value available during the constructor is initializeData (as the passed in value).

If you have one-off initialization that you want to do, but based on attributes, then you can write your own Initialize method (that simply exits if already initialized).