Change Logging from a Web Service

Topics: Logging Application Block
Feb 13, 2007 at 5:42 PM
Edited Feb 13, 2007 at 6:00 PM
Hi, I am implementing a WebService that requires high availability. I want to include some methods in the service which will allow me (using appropriate authentication) to change the logging configuration and also retrieve the log. I can get the log file once I can read the configuration to see where the file is written. How can i read the configuration? More importantly, how can I programmatically change the log settings to include more verbose logging? I know how to do all this with the config file, but I'd like to be able to do it by calling a method of my web service so I can do it remotely. Can anyone help?

Note that I have read David Hayden's articles about creating all the log objects programmatically and would PREFER not to do it that way if possible.
Feb 14, 2007 at 2:14 PM
You can read the Logging Application Block Configuration Settings as follows:

IConfigurationSource mySource = ...;
LoggingSettings settings = LoggingSettings.GetLoggingSettings(mySource);

For normal web.config / app.config deployment you would use:

LoggingSettings settings = LoggingSettings.GetLoggingSettings(new SystemConfigurationSource());

There are a number of collections and properties on the class that you can read depending on what you need.

As far as writing changes back, I have not done it during run-time so I am unsure of the best way at this moment.

It is done via serialization at design time, and you can check the source code for more information on that.




David Hayden
Microsoft MVP C#