Search code examples
c#.netlog4net.net-assembly

How do I load an assembly in app.config?


Here is the full story: I am trying to implement a custom appender for log4net. That appender used to be in the same project as the App.config and everything was working great, but now I moved it in another project (class library) which I am referencing. The name of my shared project is Lib and my appender is contained in the Lib namespace so I reference it that way:

<appender name="ColoredConsoleAppender" type="Lib.ConsoleAppenderWithColorSwitching">

log4net tells me that my Lib isn't loaded into the assembly, here is the exact error:

log4net:ERROR Could not create Appender [ColoredConsoleAppender] of type [Lib.ConsoleAppenderWithColorSwitching]. Reported error follows. System.TypeLoadException: Could not load type [Lib.ConsoleAppenderWithColorSwitching]. Tried assembly [log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a] and all loaded assemblies

Right at the start of my program I have checked the loaded assemblies using:

AppDomain.CurrentDomain.GetAssemblies();

And my library is indeed not loaded.

How can I load my class library so I can use my appender in my App.config file?


Solution

  • I have been able to resolve my problem by specifying the assembly after the name of the type:

    <appender name="ColoredConsoleAppender" type="Lib.ConsoleAppenderWithColorSwitching, Lib">