I am creating an application that uses add-ins with the .Net Add-Ins Framework. I want to track what goes on inside the add-in using log4net, but I cannot get the logged data to write to the output file. I am using log4net successfully with the host.
In my add-in's assemblyinfo.cs I've added this line of code:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
This should tell log4net to get the configuration from the .config file.
My app.config for the add-in looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="UpdateModuleLog.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
<log4net>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern
value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="TraceAppender"/>
</root>
</log4net>
</configuration>
The add-in's app.config gets moved to the pipeline as expected.
In my addin, I have the following code to instantiate log4net:
private static readonly log4net.ILog log = log4net.LogManager.GetLogger
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Finally, I call log4net in my code like this:
log.InfoFormat("Starting Update Module Version 1.0.0 for Internationalization Database.");
The problem is that UpdateModuleLog.log is never created. I would expect it to be created either in the host application's bin folder, or the add-ins folder in the pipeline, but it doesn't exist in either place. I'm using the TraceAppender because I want to log anything written to Debug or Trace to the same file, but if this requires writing to a separate file then so be it.
Also, the log file for the host process does NOT reflect any of the logging done from the Add-Ins.