Reputation: 8162
I created a very simple appender from subclassing AppenderSkeleton
. I put this into an extra library and referenced it. The relevant part of my app.config
in the program where I use it is:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="${LOCALAPPDATA}\MyProgram\MyLog.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline%exception" />
</layout>
<threshold value="Debug" />
</appender>
<appender name="MySimpleAppender" type="Some.Namespace.SimpleAppender" >
<threshold value="Info" />
</appender>
<root>
<appender-ref ref="FileAppender" />
<appender-ref ref="MySimpleAppender" />
</root>
</log4net>
The configurator is setup in Program.cs
like this:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
When I now log something, e.g.:
LOG.Info("foo");
the message gets written to the file (using the FileAppender
), but my SimpleAppender
is ignored. When I explicitly create a nullary constructor and set a breakpoint to it, I see that it is not even instantiated. When I copy the class file directly into the project where my program resides in, it works.
What am I missing?
Upvotes: 1
Views: 1794
Reputation: 3290
You need to add the assembly name to the type tag. Right now it is looking in the Log4Net assembly.
It takes the format
type="Namespace,AssemblyName"
So much like
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
You need
<appender name="MySimpleAppender" type="Some.Namespace.SimpleAppender,MyAssembly" >
Upvotes: 4