logging configuration files

Topics: Logging Application Block
Jul 26, 2010 at 12:46 PM

Hi -

I'm new to EntLib, I couldn't find an answer, sorry if this is a repeat question

I have an application which is used in different scenarios, some datasources and behavior change, but overall the application logic is the same. Some functionality I want to determine at program start due to parameters I set on the command line, ie. which kind of logging I do.

I want to write

   myapp

to run the normal program (with the general logging from the config file)

   myapp c:\verboselog.config

to load the specified configuration file to do verbose logging, or

   myapp c:\debuglog.config

to load another specified configuration.

Idealy the config files only contain the loggin specification, and I can invent new files as I need them.

I hope I made myself clear. How would I setup something like it?

 

thx

wolfma

 

 

Jul 27, 2010 at 1:35 AM

Hi wolfma,

The way I understand it what you want is to be able to use multiple logging configuration located in different config files. Is my understanding correct? If yes, then one approach I can give you is the example given in this blog on Using Several ConfigurationSources. As for logging app block it may look something like this;

            FileConfigurationSource file = new FileConfigurationSource(@"External.config");
            LogWriterFactory writerFactory = new LogWriterFactory(file);
            LogWriter writer = writerFactory.Create();

            LogEntry log = new LogEntry();
            log.Categories.Add("General");
            log.Severity = System.Diagnostics.TraceEventType.Critical;
            log.Message = "Test ConfigSource";
            writer.Write(log);

Also one other approach you can try if you would opt not to use any configuration file is by utilizing EntLib 5's Fluent Configuration API. You can check the documentation to see if it will work for you http://msdn.microsoft.com/en-us/library/ff664363(v=PandP.50).aspx.

 

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com