tags:

views:

51

answers:

1

Dears

I am using log4net in my c# application i have different logger which insert text lines in my single log file.

But now i wanted to add a new logger which should not post log entries in the same file rather i should log in a different file so i configured a new fileAppender, After doing whatever i found on the net i am able to create a different file for my new logger but it echoes the same value in first log file too.

so please if anybody knows about the use of LogFilters so that i could add "Logger <> New logger " match in previously configured appender.

Regards Mubashar

+1  A: 

Assuming you have your "special" logger like this:

ILog logger1 = LogManager.GetLogger("namespace.special_class");

then you can configure log4net as follows:

<logger name="namespace.special_class" additivity="false">
   <appender-ref ref="RollingFileAppender4SpecialMessages" />
</logger>

<root>
   <level value="ALL" />
   <appender-ref ref="StandardRollingFileAppender" />
</root>

This way your special class will use its own file appender. If you need the log messages from this class in your normal log file, then you need to remove the "additivity" attribute.

Stefan Egli
hmm Root Logger i was unaware of this fact and i never thought to have a logger name in config actually i have many different class and each and every class i used ILog logger = LogManager.GetLogger(typeof(myClass)) that is why i was looking for LoggerFilter with Not Equal condition. so is there any way to do that? anyway thanks for answer.
Mubashar Ahmad
so that means you have a logger in every class which is certainly good. but how would you decide what should go to the second file? Do you have other loggers with different names or do you want to have messages from a certain "namespace" in the second file?
Stefan Egli
Yes every class have different logger and there is a hard line that a particular class logger should write in second file all other should go to first file. that is why i was looking for not equal match :(
Mubashar Ahmad
see my revised answer
Stefan Egli