Log4Net Multiple Appenders, multiple tables having issues with config

1.4k Views Asked by At

I have two different tables that I'm logging information too. I'm using the Common.Logging library wrapper for log4net and almost have things configured properly but I'm running into an issue where to much is getting logged to the log table... I know, counter-intuitive... I have two tables

Log Table Audit Table

The following is my configuration

<log4net>
<!-- This will force both loggers to write to both tables-->
<root>
  <level value="INFO" />
  <appender-ref ref="LogAppender" />
  <!--<appender-ref name="Audit" ref="AuditAppender" />-->
</root>
<logger name="Log">
  <level value="INFO" />
  <appender-ref ref="LogAppender" />
</logger>
<logger name="Audit">
  <level value="INFO" />
  <appender-ref ref="AuditAppender" />
</logger>
<!--SQL LOG TABLE Appender-->
<appender name="LogAppender" type="log4net.Appender.AdoNetAppender"> ....  This writes to Log Table correctly
</appender>
<appender name="AuditAppender" type="log4net.Appender.AdoNetAppender"> ....  This logs to the Audit Table correctly
</appender>
</log4net>

The Calling code: We have three ways to create a logger

    readonly ILog _default = LogManager.GetCurrentClassLogger();
    readonly ILog _logger = LogManager.GetLogger("Log");
    readonly ILog _auditer = LogManager.GetLogger("Audit");

Now if I call all three back to back

    _default.Info("Default Logger");
    _logger.Info("Test get products logging");
    _auditer.Info("Test get products audit");

I'm trying to get it so the _default or _logger both write to the Log Table, which actually they do AND The _auditer logger writes to the audit table...

But here's the problem... with the configuration the way I have it, the audit table ALSO writes to the LOG table, which is what I don't want. Now if I get rid of the root node in the log4net config so I ONLY have the named loggers everything works fine in that the _logger log writes to the log table, and _auditer writes to the audit table, but the _default log doesn't write to ANYTHING... so what am I missing here???

1

There are 1 best solutions below

1
On BEST ANSWER

You should set additivity = false to prevent your audit logger from inheriting the configuration of the root logger.

<logger name="Audit" additivity="false">
   ...
</logger>