2

I'm working on a C# application that will have quite a few log files. These log files will be created in the same file path, and this file path will be determined at configuration time.

Is there a way I could specify this log files basepath in a single location the log4net configuration e.g. in a property?

I'd, of course, be referencing this basepath in the file param of each logfile appender?

One option I've considered is setting this path in the app.config/web.config, which the application will transfer into a log4net global context property. However, that would mean making sure that all loggers are created AFTER this property is set.

Any comments on the preferred, or the fallback method are welcome.

cheers!

musaul
  • 2,341
  • 19
  • 26

1 Answers1

0

You can implement a log4net custom pattern converter to return the basepath for logfiles. This is explained here: https://stackoverflow.com/a/4389828/910348.

The difference for your scenario is that your converter can simply read the basepath from your app.config/web.config.

Cheers!

Community
  • 1
  • 1
ThisGuy
  • 2,335
  • 1
  • 28
  • 34