Changing Configuration At Runtime Without Overwriting Config File

Topics: General discussion, Logging Application Block
Sep 25, 2009 at 5:43 PM

Hi,

I'm trying to figure how to change the LAB to add change the value of the priority filter at runtime. From the following threads:

How to add listeners through code?

Add new category sources dynamically

And the Updating Configuration Settings at Run-time section of the help file for EntLib all show having to overwrite the configuration file in order to be able to change the runtime settings...Which isn't what I want. I want the runtime settings to persist only for that instance of the application. I don't want to have to change the config file since that will affect the app the next time it is started...How do you do this in EntLib?

Thanks in advance,

Carlos

Sep 28, 2009 at 8:25 AM

Hi,

I think that is not possible. The changes must be first persisted to the config file before the LAB can detect configuration change. Is using the LAB programmatically not an option for you?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 28, 2009 at 4:16 PM

I really didn't want to have to modify the config file as I wanted the changes to be only for the current execution of the app. Touching the config means that the next time the app runs, the changes will stick. My goal was to have the config act as the default which could be changed at runtime for the current execution.

Thanks though,

Carlos

Oct 1, 2009 at 1:23 AM

Updating configuration settngs at runtime means that you will not modify the app.config, you will modify the runtime configuration (.exe.config).  Thus, your changes will only exist during the current execution, your app.config remains unchanged.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 1, 2009 at 3:49 AM

Well...That's true if you're only looking at it from the point of view of me running the app from the debugger, where yes, the app.config and the .exe.config are different files...however, once the app is deployed, they are pretty much one in the same. If I write code to modify the .config file just to get LAB to identify a change in filtering or anything, I'm modifying the .exe.config which means my changes get persisted across multiple executions....

Oct 1, 2009 at 5:17 AM

I see.  What you can do is have a backup of your original config, run a bootstrap at startup of your application that overwrites the .exe.config with the backup you created.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com