Logging Application Block - Logger fail safe

Topics: Logging Application Block
Aug 9, 2007 at 12:01 AM
I have just finished my research on the Logging Application Block and I love it. I am looking at creating wrappers around Logger and LogEntry classes to make the migration from our current system a little easier. My question is:

How can I create Logger that would contain all necessary components to log to a file, without using a configuration file? I just wanted to make sure that if a configuration file was deleted the logger would still have a fail safe. I am not looking for a detailed solution, but just where to start looking.

Thanks Travis
Aug 10, 2007 at 6:03 PM


travis25 wrote:
I have just finished my research on the Logging Application Block and I love it. I am looking at creating wrappers around Logger and LogEntry classes to make the migration from our current system a little easier. My question is:

How can I create Logger that would contain all necessary components to log to a file, without using a configuration file? I just wanted to make sure that if a configuration file was deleted the logger would still have a fail safe. I am not looking for a detailed solution, but just where to start looking.

Thanks Travis

Anyone?


Aug 10, 2007 at 8:03 PM
Edited Aug 10, 2007 at 8:03 PM
Hi,

The Logger facade will always attempt to use the configuration file and fail if no configuration is found. However you can assemble a LogWriter instance yourself, or use the LogWriterFactory with a properly configured DictionaryConfigurationSource, if you don't wan to rely on the configuration file.

If you don't want to change EntLib's code, you could "clone" the Logger class and add some custom configuration source handling and use that facade instead of the standard one. You don't necessarily have to copy all the methods, just the ones you intend to use. I haven't checked that all the necessary classes are public, but the LogWriterFactory is.

Regards,
Fernando
Aug 13, 2007 at 5:19 PM
Edited Aug 13, 2007 at 5:19 PM
I do not want to modify the logger application block. Is there a way to interact with the configuration elements? If so, I could write a utility that would check a specify location for the configuration file and its contents. If a particular element was not available I could then make the modifications needed and update the configuration file. I am aware that I can use ConfigurationManager class and write a custom utility. Does the logging application block have a more elegant way of modifying the underlying configuration elements?

Thanks again,

Travis
Aug 13, 2007 at 7:26 PM
Hi,

I'm not sure I understand what you have in mind. If you don't have a configuration file you can't really do much through the ConfigurationManager class, and even if you do you'd have to update the configuration file and reload it. The blocks do provide a level of insulation from the actual configuration file through the use of configuration sources, but you still need a minimal level of configuration to leverage this insulation, namely the section describing the configuration sources (i.e. meta configuration). You could create a new IConfigurationSource implementation to do the manipulation you are describing; the ManageableConfigurationSource is an example of such source.

The approach I suggested is to clone the Logger static class and use this new class instead, but using the objects and factories of the block from the released assembly. This would be similar to the "wrapper" classes you initially described.

Regards,
Fernando