Creating a custom Formatter in Ent Lib 3.1

Topics: Logging Application Block
Sep 2, 2008 at 10:10 PM
I am attempting to select a Custom Formatter that I have implemented in Comp.Common.EnterpriseLibrary.  I am receiving an error message "There were no types found in the assembly 'Comp.Common.EnterpriseLibrary' that implement or inherit from the base type 'Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.LogFormatter'."   I have made sure to reference the source Common,Logging projects from the entlib source folder and inherit from LogFormatter. In addition, i am using the Config tool from the entlibsrc\bin folder as well.

Sep 3, 2008 at 12:53 PM

You need to make sure your class is annotated with the ConfigurationElementType attribute configured with the CustomFormatterType class.

Sep 3, 2008 at 7:05 PM
I have ensured that  "[ConfigurationElementType(typeof(CustomFormatterData))]" is decorated on the implementing class.  I have tried both, implementing the ILogFormatter and inheriting from LogFormatter all with no avail.
Sep 3, 2008 at 7:53 PM

That's strange. I just created a repro proyect and it worked for me; I added the existing Common and Logging projects to the solution and added references to them, and ran the configuration tool from the bin folder.

This is what the formatter class looks like

using System;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

using Microsoft.Practices.EnterpriseLibrary.Logging;

using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

using Microsoft.Practices.EnterpriseLibrary.Logging.Formatters;


namespace MyFormatter



    public class MyLogFormatter : LogFormatter


        public override string Format(LogEntry log)


            throw new NotImplementedException();




Sep 3, 2008 at 9:20 PM
Ok, I think I have an idea what happened here.
It appears that user must inherit from LogFormatter and not just implement ILogFormatter.  Initially, I have implemented from ILogFormatter and then ran the config console.  It returned with no types found.  Then, I went back to VS2k5 and modified the class to inherit from LogFormatter.  However, I did not shutdown the config console.  I just clicked again on Load Assembly.  I believe that AppDomain did not allow a new assembly to load, thinking there is already one loaded with the same name.  I received that error message again.  Pardon my lack of experience.  Now, I have not dug through the EntLib code too much but is there a reason why documentation says ILogFormatter but console expect LogFormatter?
Also, I am investigating another similar situation with inheriting from CustomTraceListener.
May 11, 2009 at 2:53 PM

So I'm having the same issue - what was the solution?

 I  have CustomFormattedData attributem, Inheret from LogFormatter and have defined a Format (LogEntry log) method -

What am I missing?<font size="2">



ConfigurationElementType(typeof(CustomFormatterData))]<font size="2">



public class LogXmlFormatter : LogFormatter






May 12, 2009 at 3:11 AM

Try closing and reopening Visual Studio.  The type it is looking for is indeed of type LogFormatter as it is what is specified in the Type property of the CustomFormatterNode.  Not sure if the documentation is wrong or they should correct the code. 


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.