I updated some of my custom types for Enterprise Library today from version 1.1 to 2.0. I have a custom logging formatter that takes log entries and formats them as XML. I ran into a rather nasty error message when the formatter was auto-constructed with the new 2.0 Enterprise Library. Although I had followed it rather closely, the Enterprise Library 2.0 documentation does not state that the constructor for the custom formatter must include a paramter of type NameValueCollection since that will hold the configuration data for the formatter. This is true, of course, regardless of whether or not you are using the configuration data. So, the custom formatter should look like:
[ConfigurationElementType(typeof(CustomFormatterData))]public class XMLFormatter : LogFormatter
{
public XMLFormatter(NameValueCollection nvc)
{
// Nothing to do in my case
}
public override string Format(LogEntry log)
{
// Implementation of Format()...
}
}
Make sure you add the ConfigurationElementType attribute to your custom formatter class since it is also required by the Enterprise Library object builder.
Read More...
[Source: Stuart Jones Weblog - Posted by Kishore Vengala]
No comments:
Post a Comment