How do I configure log4net from an arbitrary data structure?
I'm used to working in Python, but my current project is in C#/.NET and uses log4net for logging. Out of the box, log4net uses an XML file for configuration. I dislike XML and want to use something else -- possibly JSON or YAML.
In Python I would do this by loading a dictionary with certain keys from whatever external file I feel like (typically json or yaml), and passing it to
logging.dictConfig, like this:
# logging.yaml root: level: INFO handlers: [file] handlers: file: filename: /var/log/appname/appname.log ...more... # appname.py with open('/etc/appname/logging.yaml') as f: cfg_dict = yaml.load(f.read()) logging.config.dictConfig(cfg_dict)
Note how the file-loading step is orthogonal to the logging-configuration step; this example uses a yaml file, but it could just as easily have been json.
How would I do the equivalent for log4net? My assumption is that, internally, log4net loads its XML file into some data structure (maybe not a dict, but some equivalent of
cfg_dict above) and then passes that structure to whatever code manages the configuration (the equivalent of
If I know what "that structure" is, and what function expects to receive it, then I can separate the two steps and build it myself from whatever file format I want. If that's not possible (or not simple), is there an alternative logging library that does support this?