Creating a custom Formatter in Ent Lib 3.1

Topics: Logging Application Block
Sep 2, 2008 at 11: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 1:53 PM
Hi,

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

Fernando
Sep 3, 2008 at 8: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 8:53 PM
Hi,

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

{

    [ConfigurationElementType(typeof(CustomFormatterData))]

    public class MyLogFormatter : LogFormatter

    {

        public override string Format(LogEntry log)

        {

            throw new NotImplementedException();

        }

    }

}

Sep 3, 2008 at 10: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 3: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">

[

</font>

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

 

</font>

public class LogXmlFormatter : LogFormatter

{

..

}

 

 

May 12, 2009 at 4: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.

entlib.support@avanade.com