1

I am having some trouble with the following root config setup:

<root>
  <level value="INFO" />
  <appender-ref ref="file-appender-info" />

  <level value="WARN" />
  <appender-ref ref="file-appender-warn" />

  <level value="ERROR" />
  <appender-ref ref="file-appender-error" />

  <level value="DEBUG" />
  <appender-ref ref="ConsoleAppenderStandard" /> 
</root>

It is writing all the levels of logs into ALL of the file Appenders.

So for example info-log.txt has logs from Log.Warn and Log.Error

Im sure I have a simple issue with the layout of the config, but I cant seem to find out what it is.

Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • I think this is what you are looking for: [link](http://stackoverflow.com/questions/1372435/configure-log4net-to-write-to-multiple-files) Cheers Martin [1]: http://stackoverflow.com/questions/1372435/configure-log4net-to-write-to-multiple-files – Martin E Sep 22 '14 at 17:42
  • I believe that is the opposite of what I want to achieve. Mine is writing to multiple files, I want each levels logs to go to a specific file. – Zapnologica Sep 22 '14 at 17:55
  • There is another answer in that post that explains what you want? [link](http://stackoverflow.com/a/4513361/3877877). You have to call the LogManager.GetLogger("SECTION") – Martin E Sep 22 '14 at 17:57

1 Answers1

2

You are defining the level of logging repeatedly in the root, which then keeps only the latest one and uses it for all appenders. Only one level can exist for one logger.

If you want to filter each level to one appender, declare all appenders in the root and use a LevelMatchFilter on each appender to have only one level type pass into each appender.

You may be interested in other filters, here is a list taken from the link above:

Here is a list of the filters available in the log4net distribution:

  • log4net.Filter.LevelMatchFilter Filters log events that match a specific logging level; alternatively this can be configured to filter events that DO NOT match a specific logging level.
  • log4net.Filter.LevelRangeFilter Similar to the LevelMatchFilter, except that instead of filtering a single log level, this filters on an inclusive range of contiguous levels.
  • log4net.Filter.LoggerMatchFilter Filters log events based on the name of the logger object from which they are emitted.
  • log4net.Filter.StringMatchFilter Filters log events based on a string or regular expression match against the log message.
  • log4net.Filter.PropertyFilter Filters log events based on a value or regular expression match against a specific context property.
  • log4net.Filter.DenyAllFilter Effectively drops all logging events for the appender.
samy
  • 14,832
  • 2
  • 54
  • 82