Log4net: error loading user application

I expanded AppenderSkeleton to create a custom application called HTTPAppender, but something has to do with the link to it in the XML file. Log4Net obviously cannot find my custom appender. Is there a way to reference it from the xml file to point to my project, or do I need to add my own appender source code in log4net so that it is packaged in log4net.dll?

I get the following error in the Immediate window while debugging:

log4net: ERROR XmlHierarchyConfigurator: Could not create Appender [HTTPAppender] of type [HTTPAppender.HTTPAppender, HTTPAppender]. Reported error follows.
System.IO.FileNotFoundException: Could not load file or assembly 'HTTPAppender' or one of its dependencies. The system cannot find the file specified.
File name: 'HTTPAppender'
   at System.RuntimeTypeHandle._GetTypeByName (String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark & ​​stackMark, Boolean loadTypeFromPartialName)
   at System.RuntimeTypeHandle.GetTypeByName (String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark & ​​stackMark)
... etc

Here is the log4net section of the xml file:

<log4net> <appender name="HTTPAppender" type="HTTPAppender.HTTPAppender,HTTPAppender"> <evaluator type="log4net.Core.LevelEvaluator,log4net"> <threshold value="WARN"/> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="#%level - %message" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="HTTPAppender" /> </root> <logger name="log4netErrorLog" > <level value="DEBUG" /> <appender-ref ref="HTTPAppender" /> </logger> </log4net>

+5
source share
6 answers

If you use any non-standard assemblies, put them in the application directory along with your assembly. If this does not help, try giving your assembly a strong name and use the fully qualified name in the log4net configuration file. You can also try putting it in the GAC.

+6

, . "HTTPAppender" , ?

+2

. log4net.dll, , , log4net.dll, .

+1

, , .

HTTPAppender .

I am sure that this error "Could not create Appender" because it does not have a default constructor

0
source

I have encountered the same problem recently. I fixed this by adding the assembly name after the fully qualified type name with a semicolon in the type attribute. Please see below.

<log4net>
    <appender name="LogFileAppender" type="TestHarness.Model.CustomRollingFileAppender, TestHarness.Model">
 </log4net>
0
source

Source: https://habr.com/ru/post/1729516/


All Articles