You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by DaveS <da...@dnvgl.com> on 2016/11/04 08:15:30 UTC

Issue with Custom Appender

I have created a custom appender to work alongside two other appenders. The
problem I have having is that the custom appender isn't receiving any logs.

My custom appender simply inherits from AppenderSkeleton. However, I have
also tried creating my own appender that implements IAppender.


My application is a Windows Form application, written in C# using VS2015. I
am targetting .Net 4.5.2. "Any CPU"

I am using Log4Net version v2.0.5 from NuGet (version 1.2.15.0)

Within the application config I have

 <root>
      <level value="DEBUG" />
      <appender-ref ref="MemoryAppender" />
      <appender-ref ref="RollingFileAppender" />
      <appender-ref ref="AdoNetAppender" />
    </root>

    <appender name="MemoryAppender"
type="[namespace].CustomAppender,[assemblyname]">
    </appender>


My custom appender is being found as the program stops at a break point in
the constructor. However, the overridden Append() is never called.

The OUTPUT window contains the following details:
Exception thrown: 'System.InvalidCastException' in log4net.dll
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[MemoryAppender] of type [<namespace>.CustomAppender,<assemblyname>].
Reported error follows.
System.InvalidCastException: Unable to cast object of type
'<assemblyname>.CustomAppender' to type 'log4net.Appender.IAppender'.
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [MemoryAppender] not
found.



Any suggestions to fix this issue would be gratefully received.




--
View this message in context: http://apache-logging.6191.n7.nabble.com/Issue-with-Custom-Appender-tp70625.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Re: Issue with Custom Appender

Posted by Dominik Psenner <dp...@gmail.com>.
Glad you were able to sort this out!

Cheers

On 2016-11-04 14:32, DaveS wrote:
> Solved.
>
> I had a reference to version 1.2.10 which was causing this version to be
> loaded from the GAC.
>
>
>
>
>
>
>
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/Issue-with-Custom-Appender-tp70625p70639.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Issue with Custom Appender

Posted by DaveS <da...@dnvgl.com>.
Solved.

I had a reference to version 1.2.10 which was causing this version to be
loaded from the GAC.







--
View this message in context: http://apache-logging.6191.n7.nabble.com/Issue-with-Custom-Appender-tp70625p70639.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Re: Issue with Custom Appender

Posted by DaveS <da...@dnvgl.com>.
I am building the custom appender against: 
log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a

And this is the same DLL that is being loaded by the application.

I have uploaded the log file.



Dominik Psenner wrote
> Hi Dave,
> 
> would you please send us a the complete log4net internal logs including 
> debug logs?
> 
> Anyway it smells like an issue with incompatible binaries. 
> log4net.txt
> <http://apache-logging.6191.n7.nabble.com/file/n70628/log4net.txt>  
> 





--
View this message in context: http://apache-logging.6191.n7.nabble.com/Issue-with-Custom-Appender-tp70625p70628.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Re: Issue with Custom Appender

Posted by Dominik Psenner <dp...@gmail.com>.
Hi Dave,

would you please send us a the complete log4net internal logs including 
debug logs?

Anyway it smells like an issue with incompatible binaries. You could 
check if both the log4net assembly that your custom appender was linked 
against and the log4net assembly that your application was linked 
against are the same. There is a log4net assembly with strong name out 
there and one that has no strong name. Or you may have even linked your 
appender against a log4net assembly that you have built from source?

Cheers

On 2016-11-04 09:15, DaveS wrote:
> I have created a custom appender to work alongside two other appenders. The
> problem I have having is that the custom appender isn't receiving any logs.
>
> My custom appender simply inherits from AppenderSkeleton. However, I have
> also tried creating my own appender that implements IAppender.
>
>
> My application is a Windows Form application, written in C# using VS2015. I
> am targetting .Net 4.5.2. "Any CPU"
>
> I am using Log4Net version v2.0.5 from NuGet (version 1.2.15.0)
>
> Within the application config I have
>
>   <root>
>        <level value="DEBUG" />
>        <appender-ref ref="MemoryAppender" />
>        <appender-ref ref="RollingFileAppender" />
>        <appender-ref ref="AdoNetAppender" />
>      </root>
>
>      <appender name="MemoryAppender"
> type="[namespace].CustomAppender,[assemblyname]">
>      </appender>
>
>
> My custom appender is being found as the program stops at a break point in
> the constructor. However, the overridden Append() is never called.
>
> The OUTPUT window contains the following details:
> Exception thrown: 'System.InvalidCastException' in log4net.dll
> log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
> [MemoryAppender] of type [<namespace>.CustomAppender,<assemblyname>].
> Reported error follows.
> System.InvalidCastException: Unable to cast object of type
> '<assemblyname>.CustomAppender' to type 'log4net.Appender.IAppender'.
>     at
> log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
> appenderElement)
> log4net:ERROR XmlHierarchyConfigurator: Appender named [MemoryAppender] not
> found.
>
>
>
> Any suggestions to fix this issue would be gratefully received.
>
>
>
>
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/Issue-with-Custom-Appender-tp70625.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.