1

Is there any possibility to create single log4net.config file containing multiple configurations. I would like to create different logs depending on some kind of parameter that will choose proper configuration with appenders from logger config file.

e.g. I have two different projects, in each of them I need to create different logs. By reading the same for both projects config file in assembly.info and giving some kind of parameter i could choose different logger configurations to be used in projects.

I would be grateful for any help with it.

stuartd
  • 70,509
  • 14
  • 132
  • 163
MrPug
  • 487
  • 2
  • 8
  • 23
  • It's not really clear what you're trying to accomplish - you can define as many appenders and loggers as you wish to in the configuration and swap them around at runtime with code, is that what you're after? – stuartd Nov 18 '15 at 11:27
  • you can have only 1 config but different filters to deal with different cases – mikus Nov 18 '15 at 14:52
  • @stuartd what ' trying to acomplish is to have one log4net.config file in solution which will be added (Add existing) to each project. This file should contain each project logger configuration and project should choose the one that is assigned to it (other loggers should be ignored). – MrPug Nov 18 '15 at 16:12
  • It sounds like you can do that, as you can define loggers per namespace, which means they will operate on a per-project basis - so loggers are called Company.Namespace.Project1, Company.Namespace.Project2 etc (the logger names are inherited so apply to the whole project) – stuartd Nov 18 '15 at 16:44
  • @stuartd it works. Thank you very much. – MrPug Nov 20 '15 at 06:44

1 Answers1

0

Basically everything you can do is mentioned here: https://logging.apache.org/log4net/release/manual/configuration.html

and examples are here:

https://logging.apache.org/log4net/release/config-examples.html

Now, initializing your Logger you can choose the config file to be used. If you want it to be all in the app config file, then you simply provide ONE configuration. However, if you need to have different behavior for different cases (projects/classes), just specify filters that will decide which appender should be used in a moment.

Filter can base on the class name, ex. check here as it was already discussed: log4net: Configure to ignore messages from a specific class

Community
  • 1
  • 1
mikus
  • 3,042
  • 1
  • 30
  • 40