I would like to alter some settings stored in my app.config file programmatically.
I don't want to edit or update the actual app.config file, what I want to do is override some attributes after the application is running. The thing that I would like to change is the level of tracing in my wcf client application. If the app.config file has tracing level to none normally, for client support I would like to enable the client to change this to warning, critical, verbose or whatever is appropriate. I don't want to change the app.confg file, the trace level of none is correct for normal operation. Its only when the client submits a support task and to get an idea of what is happening is to get the application to generate a trace with a level set to some level. How can one programmatically change this sort of thing once the application has started. I have seen a number of articles of how to set up an endpoint from scratch programmatically. I have not seen this for the systems.diagnostics section however. I have seen articles on how to modify the app.config file, either using the wcf editor or manually. What I have not seen is how one can retain what the app.config defines but when one needs to alter or override programmatically the settings contained in the ap.config file. In the following in my app.config file <system.diagnostics> <sources> <source name="NewSource" switchValue="Error,ActivityTracing"> <listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default"> <filter type="" /> </add> </listeners> </source> <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> <listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default"> <filter type="" /> </add> <add name="ServiceModelMessageLoggingListener"> <filter type="" /> </add> </listeners> </source> <source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true"> <listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default"> <filter type="" /> </add> <add name="ServiceModelTraceListener"> <filter type="" /> </add> </listeners> </source> </sources> <sharedListeners> <add initializeData="d:\sandbox\wcf\helloworld\helloworldservice\helloclient\app_ messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="DateTime, Timestamp, ProcessId, ThreadId"> <filter type="" /> </add> <add initializeData="d:\sandbox\wcf\helloworld\helloworldservice\helloclient\app_ tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp, ProcessId, ThreadId"> <filter type="" /> </add> </sharedListeners> </system.diagnostics> I would like the user to optionally adjust the switchvalue attribute to something other than the default of warning. I might want to disable it by changing this to none or to increase the content by changing it to verbose etc I might also want to change where the trace is written to in the above initializeData attribute values. Is this possible? There must be lots of times where one needs to override the attributes of various elements programmatically when the default values in app.config are usually ok but in some instances one needs to override these values programmatically without persisting changes to app.config. Any assistance very much appreciated.