Merging app.config-LoggingSettings and external LoggingSetings

Topics: Logging Application Block
Jun 10, 2010 at 2:41 PM
Edited Jun 10, 2010 at 3:03 PM

Hi,

I'm trying to merge programmatically the existing LoggingSettings of an external application (that uses my DLL. ) and LoggingSettings I read from an extra .config file. Using this extra config, I want to make sure, my DLL would log into a specific file using my format, so I always have all I need to debug.

I wanted to read both config files and then copy the config of my dll into the LoggingSettings of the external app, but it doesn't work (readonly)

How can I do this without editing the app.config (I have no right on this file)?

Thx

Nico

 

PS: I'm using EntLib 4.1

Jun 11, 2010 at 1:35 AM

The logging block reads configuration from an instance of IConfigurationSource which is by default, an instance of SystemConfigurationSource which points to your app.config.  If you don't have the option to modify the config, you need to make use of another configuration file and pass that as an instance of FileConfigurationSource to the LogWriterFactory.  Example:

LogWriterFactory factory = new LogWriterFactory(new FileConfigurationSource("external.config"));
LogWriter logWriter = factory.Create();
LogEntry entry = new LogEntry();
logWriter.Write(entry);

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

Jun 11, 2010 at 6:54 AM

Hi,

Thanks a lot for the answer. I don't think I can do it this way because I would have to write the merged config file into the user folder or in a temp folder or something like this at runtime. The user under which the program is running has the minimum rights it needs to work on the machine.

I decided to do it another way: I create for each dll one instance of a LogWriter which searches a file named <dll-name>.dll.config, if the file is not found, it defaults on Logger.Writer. So I can automatically load a special config file at runtime for my dll and when there is no special config file, it uses the default Logger.Writer.

If you think I forgot something please tell me.

Thx

Nico

Jun 11, 2010 at 7:28 AM

I believe that should work.

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