2

I'm using log4net, I would like to have 2 logs,
- BasketballCustomer.log, for all Customers that plays Basketball;
- ChessCustomer.log, for all Customers that plays Chess.
, while for each customer, whether he/she plays Basketball or Chess, is only known until runtime.

I would like to have each log configured separately, about log file name, size, number, log level, etc.

Also, I'd prefer such set up done by C# code, not config file.

How could I do that?

I tried search on net, there are some articles but none meet exactly my requirements
- Log4Net and multiple log files talked about multiple log files but it does not toggle during runtime;
- Configure Log4net to write to multiple files is similiar but it's done in config file....

Please kindly suggest, many thanks!

Community
  • 1
  • 1
athos
  • 6,120
  • 5
  • 51
  • 95

1 Answers1

2

You can do this by using an environment variable in the log4net.config and then set the value of the environment variable through the C# code

So somewhere in your C# class, do something like:

Environment.SetEnvironmentVariable("log_file_name", "MyLogFileName");

And then in the log4net.config that is used, specify the value to the name of the environment variable. The syntax would be something like this:

<param name="File" value="${log_file_name}".log/>

Mark Harrell
  • 331
  • 1
  • 3