I have 2 appender in my config file which is configured to insert to different tables, "Log" and "LogFirms", but somehow both of the loggers are inserting to both of the tables.
<log4net debug="true">
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception],[ClientIp],[Username],[Controller],[Action],[Parameters]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @clientip, @username, @controller, @action, @parameters)" />
...
</appender>
<appender name="AdoNetAppenderForFirms" type="log4net.Appender.AdoNetAppender" additivity="false">
<bufferSize value="1" />
<commandText value="INSERT INTO LogFirms ([Date],[Thread],[Level],[Logger],[Message],[Exception],[ClientIp],[Username],[Controller],[Action],[Parameters]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @clientip, @username, @controller, @action, @parameters)" />
...
</appender>
<root>
<level value="ALL" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="AdoNetAppenderForFirms" />
</root>
</log4net>
Here is the logger class;
public static class Logger
{
private static ILog log { get; set; }
private static ILog logFirms { get; set; }
static Logger()
{
log = LogManager.GetLogger("AdoNetAppender");
logFirms = LogManager.GetLogger("AdoNetAppenderForFirms");
}
public static void Error(string controller, string action, string parameters, object msg, Exception ex)
{
if (controller == "AccountController" && logFirms.IsErrorEnabled)
{
logFirms.Error(msg, ex);
}
else if (log.IsErrorEnabled)
{
log.Error(msg, ex);
}
}
There is no error seen in the controller, so the problem must be in the configuration... I searched and tried adding
additivity="false"
property to the "AdoNetAppenderForFirms" element but that changed nothing. So do you have any advice to fix this?
additivityas that's for child loggers, but you're only defining root. You can put a breakpoint in the logger class and inspect the aenders attached to each logger, and if they're OK then enable log4net internal debugging and have look at that for any clues. - stuartd