I have a project Commonthat contains log4net CustomAppender. I reference the project in all my other projects and am setting up the log4net application in app.config. Everything works smoothly, with the exception of one project that does not work when trying to create an instance of Appender.
The output shows the following error:
System.TypeLoadException: Could not load type [Common.Appenders.MyCustomAppender].
Tried assembly [log4net, Version = 1.2.11.0, Culture = neutral, PublicKeyToken = 669e0ddf0bb1aa2a]
and all loaded assemblies
at log4net.Util.SystemInfo.GetTypeFromString (Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString (String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender (XmlElement appenderElement)
log4net: ERROR Appender named [MyCustomAppender] not found.
The log4net configuration is the same for all projects. app.configcontains:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="MyCustomAppender" type="Common.Appenders.MyCustomAppender">
<file value="log.txt" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="MyCustomAppender" />
</root>
</log4net>
</configuration>
From the code I call log4net.Config.XmlConfigurator.Configure(). If I manually load the assembly with Assembly.Load("Common")before calling the log4net configuration for a non-working project, everything is fine.
Any idea why the assembly doesn't load when MyCustomAppendercreated through reflection? How can i solve this?
source
share