Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to create a log for each instance of a class in log4net?

Tags:

c#

log4net

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.

like image 981
uriDium Avatar asked May 26 '11 09:05

uriDium


People also ask

Does log4net support structured logging?

log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.

What are the main components of log4net briefly describe how loggers work in log4net?

Log4net has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.

Is log4net dependent on log4j?

Log4net is a logging utility for . NET applications. It's based on log4j, which is for Java applications. Log4net is highly configurable, so you can use it in many scenarios.


1 Answers

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 :)

like image 109
Basit Anwer Avatar answered Nov 04 '22 01:11

Basit Anwer