0

I have a component, which my application create multiple instance...

What i want is to log each compoent instance to different file..

To be more clear,

  • My application create same component instance such as c1,..ck,....cn...
  • Each instance should log into diffferent log file such as ck will log to file logfile-k
  • But ck should not log to other log files such as ck-1 or ck+1 -
  • I should able to give dynamically log file names

How can i do it in Log4j or log4net?

Novalis
  • 2,265
  • 6
  • 39
  • 63
  • I guess you will find what you are looking for here: http://stackoverflow.com/questions/6191874/log4net-unique-log-file-for-each-instance-of-class – Stefan Egli Jan 11 '12 at 17:11

1 Answers1

0

In log4net, would your purpose be served well-enough by use of NDCs in a single logging stream? When to use 'nested diagnostic context' (NDC)?

Otherwise, your configuration scenario is one where the normal XML configurator and the typical use case will not do what you want - you seem to be looking for an instance-sensitive appender, and setting up such an animal is not a normal configuration for either log4* framework.

Community
  • 1
  • 1
Tetsujin no Oni
  • 7,300
  • 2
  • 29
  • 46
  • NDCs does not give me any benefit..It may be odd config but is it possible in Log4* farmeworks? I try programatically set FileAppenders and able to write different files but all instances write all file appenders -log files... – Novalis Jan 11 '12 at 16:09
  • I also try changing file name...But when i set new file name to ck instance,suppose file logfile[k], intance ck-1 also start write to file logfile[k] instead of writing logfile[k-1] – Novalis Jan 11 '12 at 16:14
  • for each instance, it will need its own appender/logger pair, or the appender will need to be able to tell which instance it is supposed to be bound to. If your output format for this log put the NDC as the first element in the log message, you could use regex parsing to determine slice and dice the log further... It seems a more natural solution than the level of custom logging which seems to be suggested by what you're trying to do. – Tetsujin no Oni Jan 11 '12 at 16:25