How do you create a formatter from the FormatterName

Topics: General discussion, Logging Application Block
May 25, 2010 at 3:08 PM
Edited May 25, 2010 at 3:11 PM

Hello all,

You can create a Database object using the following:

Database myDatabase = DatabaseFactory.CreateDatabase("MyDatabaseName");

What is the equivalent to create a TextFormatter from the formatter name? I think I am looking for something like: 

ILogFormatter myFormatter = SomeLogFormatterFactory.CreateLogFormatter("MyFormatterName");

Thanks in advance for any ideas and/or suggestions!

May 25, 2010 at 4:34 PM

The formatter isn't really intended to be used directly, so there's no explicit factory for it. May I ask why you want to get the formatter (the scenario could be useful to us for future planning).

In Entlib 5, you should be able to do something like:

var formatter = EnterpriseLibraryContainer.Current.GetInstance<ILogFormatter>(formatterName);

But, as I mentioned, as it's not a public entry point this isn't guaranteed to work forever.



May 25, 2010 at 8:02 PM

Thanks for the response. I had a brain cramp. I created a subclassed FormattedDatabaseTraceListener to use within a CustomTraceListener and the FormattedDatabaseTraceListener requires an IFormatter as one of the constructor parameters. I forgot that I could just use this.Formatter.