Chaps, I saw that page, and the code makes sense, but it's an unrealistic
example as the same program makes the trace source and listens to it.

Last week I created a static TraceSource in one of my general purpose
libraries, hoping to imitate what some of the Framework classes do, then I
found that the only way to listen to the library was with a config file
wiring up the listeners. I didn't want consuming applications (including my
own) to have to bother with creating config sections, and in some cases
config files are troublesome. That's when I found it seemed impossible to
create the listeners programmatically. I'm still pondering...

I have always been rather bewildered and confused by config files since
Framework 1.0. They're convenient and readable for basic scenarios, but if
you need dynamic configuration then you're often trawling the web for magic
tricks (WCF and log4net are classic examples). Even after all these years I
still find config file examples that contain mysterious things and I wonder
"is that a standard Framework config section or did someone just invent it?"

*Greg K*

On 3 December 2014 at 09:54, Tom P <[email protected]> wrote:

> Hi Greg
>
> According to the following page you can have the defaults in the
> configuration file and override things in code as you need dynamically
>
> http://msdn.microsoft.com/en-us/library/ms228984(v=vs.110).aspx
>
> Still need entries in a config file but they can be overridden which is
> good
>
> Thanks
> Tom
>
> On 2 December 2014 at 17:38, Greg Keogh <[email protected]> wrote:
>
>> Folks, many parts of the FCL (like Remoting and WCF) write trace
>> information out to a TraceSource class, presumably like this (does this
>> look right?):
>>
>> private TraceSource ts = new TraceSource("My.Library", SourceLevels.All);
>> :
>> ts.TraceInformation("Hello world!");
>>
>> The only way I can find at the moment to listen to what a library like
>> that is tracing is to put something like this in the App's config file:
>>
>>   <system.diagnostics>
>>     <sources>
>>       <source name="My.Library">
>>         <listeners>
>>           <add name="consListener"
>> type="System.Diagnostics.ConsoleTraceListener"/>
>>         </listeners>
>>       </source>
>>     </sources>
>>   </system.diagnostics>
>>
>> Does anyone know how bypass the config section to do this in code? I've
>> been fiddling and searching the web but every example or tutorial I find
>> uses a config file.
>>
>> *Greg K*
>>
>
>

Reply via email to