Log4net doesn't log when it is used inside a VSIX extension and installed at another target VS.
I have a WPF solution. I downloaded log4net dll, I added log4net.config and had set the "Copy to Output Directory" value as "Copy always".
log4net.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net debug="true">
<root>
<level value="INFO" />
<appender-ref ref="TestAppender" />
</root>
<appender name="TestAppender" type="log4net.Appender.FileAppender">
<!--<file value="${TMP}\myapp.txt" />-->
<!--<file value="c:\temp\logger.txt" />-->
<!--<file value="${USERPROFILE}\log\Log.txt" />-->
<!--<file value="${LOCALAPPDATA}\log\log.txt" />-->
<file value="${ALLUSERSPROFILE}\Log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="1KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
And I added the below line in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
then the below code in my TestWindowControl.xaml.cs and referenced/created an instance for this in the VSPackage.cs.
public partial class TestWindowControl : UserControl
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public TestWindowControl()
{
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
log.Info("info testing");
log.Debug("debug testing");
log.Error("error testing");
log.Fatal("fatal testing");
log.Warn("warn testing");
}
}
When I run this on my machine (local) it working as expected but I install this extension and try (Server) log4net is not logging with any of the location mentioned in log4net.config. Searched online and tried different paths but still, it's not logging. Am I missing something?