我擴展了AppenderSkeleton來創建一個名爲HTTPAppender的自定義appender,但是在xml文件中引用了它。 Log4Net顯然無法找到我的自定義appender。有沒有辦法從xml文件中引用它來指向我的項目,還是我必須將我的自定義appender的源代碼添加到log4net的源代碼中,以便將其打包到log4net.dll中?log4net:加載自定義appender時出錯
我調試時得到即時窗口出現以下錯誤:
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
下面是XML文件的log4net的部分:
<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>
這另一個問題詳細解釋了一點點:https://stackoverflow.com/questions/ 20082614 /組裝未加載-C-尖銳 – BrunoJCM 2017-10-20 09:00:24