Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A 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...

1 answer  ·  posted 3y ago by ajv‭  ·  last activity 3y ago by Peter Taylor‭

Question .net log4net
#5: Post edited by user avatar ajv‭ · 2021-03-23T19:43:33Z (about 3 years ago)
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) 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:
  • class: logging.handlers.WatchedFileHandler
  • 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 `dictConfig` above).
  • 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?
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) 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 `dictConfig` above).
  • 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?
#4: Post edited by user avatar ajv‭ · 2021-03-23T19:42:23Z (about 3 years ago)
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `logging.dictConfig`.
  • How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) 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:
  • class: logging.handlers.WatchedFileHandler
  • 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 `dictConfig` above).
  • 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?
#3: Post edited by user avatar ajv‭ · 2021-03-23T19:13:05Z (about 3 years ago)
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `dictConfig`.
  • How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `logging.dictConfig`.
  • How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?
#2: Post edited by user avatar ajv‭ · 2021-03-23T19:11:53Z (about 3 years ago)
  • I'm used to working in Python, but my current project is in C#/.NET and uses log4net for logging. I dislike log4net's XML config file, and want to use something else.
  • In Python I would do this by loading a [dictionary with certain keys](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `dictConfig`.
  • How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?
  • 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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `dictConfig`.
  • How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?
#1: Initial revision by user avatar ajv‭ · 2021-03-23T18:13:20Z (about 3 years ago)
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. I dislike log4net's XML config file, and want to use something else.

In Python I would do this by loading a [dictionary with certain keys](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema) from whatever external file I feel like (typically json or yaml), and passing it to `dictConfig`.

How would I do the equivalent for log4net? Its config file has a superficially similar structure, so I'm *guessing* there's way to do this, but I haven't found one. If it is not possible (or not simple), is there an alternative logging library that does support this?