Logger without and derived logger with filter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Logger without and derived logger with filter

Andreas Tscharner
Hello World,

I am trying to create a logger without and a derived logger with a filter.
Unfortunately this does not work. What I did:

  ILog mainLogger = LogManager.GetLogger("log4net-test");
  ILog classLogger = LogManager.GetLogger("log4net-test.MainClass");

  LogTestManager ltm = new LogTestManager();

  RollingFileAppender rotateAppender = ltm.CreateRollingFileAppender();

  RollingFileAppender rfa = ltm.CreateRollingFileAppender();
  StringMatchFilter smf = ltm.CreateStringMatchFilter("TestMatch");

((log4net.Repository.Hierarchy.Logger)mainLogger.Logger).Level = Level.All;
  ((Hierarchy)LogManager.GetRepository()).Configured = true;

  var firstClass = new MainClass(classLogger);

The first logger ("mainLogger") should log everything (that works), the
second logger ("classLogger") should log everything (to the same file)
except text that contains "TestMatch". Unfortunately if I execute:

  mainLogger.Error("An unfiltered TestMatch statement");
  firstClass.PrintLoggingStatement("A filtered TestMatch statement",

I got both in my log file. If I add the filter to the first
logger/appender, both statements are filtered.

What I am doing wrong? How to fix this?

TIA and best regards
        `o_ o  )   `-.  (     ).`-.__.`)
        (_Y_.)'  ._   )  `._ `. ``-..-'
      _..`--'_..-_/  /--'_.' .'
     (il).-''  (li).'  ((!.-'

Andreas Tscharner   [hidden email]   ICQ-No. 14356454