I am attempting to use an overridden XmlLayoutBase with log4net to print a custom log. It was working yesterday but I did some restructuring and now it is blowing up. Here is what I have done so far.
AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
CustomXmlLayout.cs
namespace MyCompany.MyProduct.MyService.Utilities
public class CustomXmlLayout : XmlLayoutBase
{
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
//Write stuff
}
}
log4net.config
<?xml version="1.0"?>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logfile" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.xml'" />
<staticLogFileName value="false" />
<maxSizeRollbackups value="15" />
<layout type="MyCompany.MyProduct.MyService.Utilities.CustomXmlLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Log.cs
public static class Log
{
private static ILog log =
log4net.LogManager.GetLogger(typeof(Log));
static Log()
{
XmlConfigurator.Configure();
}
private static bool IsEnabled()
{
//Verify stuff
}
public static void Write(LogEntry entry)
{
if (IsEnabled())
log.Debug(entry);
}
}
For whatever reason the call to log.Debug never reaches the FormatXml in my custom class. Anyone have any ideas?
edit It works fine when I put the log4net configuration back in web.config, so I guess its some probably with the assemblyinfo… but I don’t see what
I ended up leaving the config section in the web.config