Good morning guys.
I wrote a single istance C# 2.0 app (call it myapp).
Myapp is called many times, and at every call generates a sort of "task" that will be executed in a separated thread.
If you call myapp several times in a short time, task are executed in parallel.
Generally I use log4net for logging purposes; I configure it loading an xml file by XmlConfigurator.Configure(<config>.xml) at startup, then I use static LogManager.GetLogger(name) in every class I need a logger, quite simple.
This scenario is challenging, instead. I need to do is this: based on one of the args received on every call (call it arg), I need to get a different RollingFileAppender that logs in a different file, e. g. .log.
Just to make an example:
1st call: myapp.exe -arg:01
- myapp creates thread1
- set a new RollingFileAppender to 01.log file, if not exists
- objects used in this thread must log in 01.log file
2nd call: myapp.exe -arg:02
- create thread2
- set a new RollingFileAppender to 02.log file, if not exists
- objects used in this thread must log in 02.log file, but not in log.01
3rd call: myapp.exe -arg:01
- create thread03
- get the RollingFileAppender to 01.log file (it already exists!)
- objects used in this thread must log in 01.log file, but not in log.02
And so on.
I don't need to leave the configuration of RollingAppender in xml file, I can create it programmatically; my idea is to use a static wrapper class, call it LogHelper, that creates appenders if they do not exist based on arg, and that dispatch right ILog istances when needed by objects (in classes I would use something like ILog log = LogHelper.GetLogger(name, arg) to get a logger to use instead o default log4net method LogManager.GetLogger(name)).
So if I have 2 istances of the same class in 2 different threads, when I log messages goes one per file, depending or arg (I will inject arg in every object, if needed).
I browse many threads here in StackOverflow, but I can't find a solution.
Can someone point me to the right direction?
Thanks in advance.