Reputation: 13420
We have a couple of long lived objects each of the same class in the system. There are only about 5 or 6 and they are connections to outside systems. I want each of those instances to have their own file that they can log to.
What is the best way to do this? I can only see adding loggers programatically as the answer right now.
UPDATE: I want to avoid using the configuration file because if I add a new connection to a different remote host then i want its log output to go to file named after the connection without having to first hack around in a config file. It would be nice if it was done automagically. I don't know maybe this can be achieved in a config file once off and that you don't need to edit it everytime.
Upvotes: 8
Views: 1770
Reputation: 6860
The best answer IS programatical logging, i went through the same problem and found it as the only solution.
For more help check this question (mine) StackOverFlow Question posted by me
and i thing yours and my problem are the same, dynamic loggers, re create loggers, dispose loggers and all that stuff at runtime :)
if any more questions, do ask, will be glad to help since i have gone through all that :)
Upvotes: 1
Reputation: 16757
I have an article that might help:
This is about changing a logfile at runtime. What you could do is pass in the file name for each instance into your log4net file. That way you could create a log file for each instance of your class.
As for your edit about not wanting to use a config file, this method gets around that issue so that you can use a config file but still have the flexibility you want.
Upvotes: 0
Reputation: 25732
I can actually see a couple of possibilities:
Upvotes: 1