logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Tscharner <a...@vis.ethz.ch>
Subject Logger without and derived logger with filter
Date Tue, 22 Mar 2016 10:34:49 GMT
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();
  rotateAppender.ActivateOptions();
 
((log4net.Repository.Hierarchy.Logger)mainLogger.Logger).AddAppender(rotateAppender);

  RollingFileAppender rfa = ltm.CreateRollingFileAppender();
  StringMatchFilter smf = ltm.CreateStringMatchFilter("TestMatch");
  rfa.AddFilter(smf);
  rfa.ActivateOptions();
 
((log4net.Repository.Hierarchy.Logger)classLogger.Logger).AddAppender(rfa);

 
((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", 
Level.Error);

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
	Andreas
-- 
       ("`-''-/").___..--''"`-._
        `o_ o  )   `-.  (     ).`-.__.`)
        (_Y_.)'  ._   )  `._ `. ``-..-'
      _..`--'_..-_/  /--'_.' .'
     (il).-''  (li).'  ((!.-'

Andreas Tscharner   andy@vis.ethz.ch   ICQ-No. 14356454

Mime
View raw message