How to Configure Log4Net Custom Object Renderer for Generic Objects?
I have a generic object: MyGenericObject(of T), how do I register a custom renderer in log4net in the config file? For example, if this was a normal object the following would work:
<renderer renderingClass="MyObjectRenderer, MyClassLibrary" renderedClass="MyObject, MyClassLibrary" />
However I don't know how to write this for Generics, I attempted this:
<renderer renderingClass="MyObjectRenderer, MyClassLibrary" renderedClass="MyObject(Of MyNonGenericObject), MyClassLibrary" />
but this happened:
log4net:ERROR XmlHierarchyConfigurator: Could not find class [MyObject(Of MyNonGenericObject), MyClassLibrary].
System.TypeLoadException: Could not load type 'MyObject(Of MyNonGenericObject)' from assembly 'MyClassLibrary'.
Does anyo开发者_如何学运维ne have any better ideas on how to achive what I want?
The syntax you are using in XML file, MyObject(Of MyNonGenericObject)
, is specific to VB .NET, just like MyObject<MyNonGenericObject>
is specific to C#.
You change your declaration to use language-independent CLR type syntax:
MyObject`1[[MyNonGenericObject, MyClassLibrary]], MyClassLibrary
(1
after `
indicates the number of type parameters.)
So the line will be:
<renderer renderingClass="MyObjectRenderer, MyClassLibrary" renderedClass="MyObject`1[[MyNonGenericObject, MyClassLibrary]], MyClassLibrary" />
精彩评论