Creating Custom Formatter Problems

Topics: Building and extending application blocks, Logging Application Block
Sep 8, 2008 at 3:39 PM
Edited Sep 8, 2008 at 3:41 PM

I've tried creating a Custom Formatter as per the documentation. The documentation says to inherit from ILogFormatter. I then compile and load the Enterprise Library Configuration utility from Visual Studio. When I click Load Assembly and point to my file it simply says: "There were no types found in the assembly.... that implement or inherit from the base type ... Formatters.LogFormatter".

This confused me as I clearly am. I did some research and it seems some people inherited from LogFormatter. To test this I created a second class that inherited but still no joy. I also checked that all of my referenced assemblies were the signed versions.

Finally I loaded the Enterprise Library Configuration utility from the Enterprise Library install directory and I was able to see the second class - inherited from LogFormatter.

This has left me rather confused. Is the official documentation incorrect? Why does the right-click shortcut from Visual studio not work? Surely implementing ILogFormatter should be sufficient. What am I missing here?

Sep 9, 2008 at 2:57 PM

You are correct in that the documentation doesn't match the implementation and that implementing ILogFormatter should be enough. The issue with the Visual Studio versoin of the tool was probably that you loaded a previous version of the assembly (most likely with a version of your formatter that implemented the interface); once an assembly is loaded in the tool's process (which happens to be Visual Studio's one) you cannot load a new version. There was a discussion about this situation a couple of weeks ago with additionl details.

I don't understand what you mean by the right-click shortcut from visual studio not working.

Sep 10, 2008 at 1:04 PM
I was referring to when you right-click on a config file in Visual Studio, it loads the Enterprise Configuration Manager. However for some reason, this "version" doesn't detect the implementation of LogFormatter.
Sep 10, 2008 at 3:36 PM

I suggested a possible cause: a previous version of the assembly that didn't include the LogFormatter-derived class was already loaded, so attempts to load a new version would not be successful. Another possible cause is that the assembly that includes the custom formatter references a version of the EntLib assemblies that doesn't match the configuration set for your solution, but that doesn't seem to be the case based on the steps you've followed.