I have a project Common which contains a log4net CustomAppender. I reference the project in all my other projects and configure log4net appender in app.config. Everything works smooth except for one project which fails when trying to instantiate the 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 project. app.config contains:
<?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 code I call log4net.Config.XmlConfigurator.Configure(). If I manually load the assembly using Assembly.Load("Common") before calling log4net configure for the non-working project everything is fine.
Any idea why the assembly is not loaded when MyCustomAppender is instantiated via reflection? How can I solve this?
, Commonlike it was done in the "type" attribute above it. I personally got quickly fed up with an xml programming language without a debugger and just configure it in code. - Hans Passant