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
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 ma...
Answer
#2: Post edited
The [documentation](https://logging.apache.org/log4net/release/manual/configuration.html) gives an example using `XmlConfigurator`:> using log4net;> using log4net.Config;>> public class MyApp> {> private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));>> static void Main(string[] args)> {> // BasicConfigurator replaced with XmlConfigurator.> XmlConfigurator.Configure(new System.IO.FileInfo(args[0]));>> log.Info("Entering application.");> Bar bar = new Bar();> bar.DoIt();> log.Info("Exiting application.");> }> }In this example the filename is passed from the command line, but you can easily replace that.If what you dislike is specifically the XML, there's probably some way of mashing it up with [Newtonsoft's JSON.Net](https://www.newtonsoft.com/json/help/html/ConvertingJSONandXML.htm) to turn a JSON file into an `XElement` and pass that to the alternative `XmlConfigurator.Configure` method.
- > 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).
- What's idiomatic in duck-typed Python is not always idiomatic in statically typed C#. Using untyped `Dictionary` in C# is not really considered good style in code which postdates `System.Collections.Generic`, and using dictionaries which mixed value types was never really good style.
- So, yes, log4net loads its XML file into a data structure, but that data structure is `System.Xml.Linq.XElement`. If you construct your own `XElement` then you can pass it to `XmlConfigurator.Configure`.
- [Newtonsoft's JSON.Net](https://www.newtonsoft.com/json/help/html/ConvertingJSONandXML.htm) has some support for parsing a JSON file into an `XElement`, but I couldn't tell you how straightforward it is to write suitable JSON.
- Serilog seems to have [built-in support for JSON configuration](https://github.com/serilog/serilog-settings-configuration).
#1: Initial revision
The [documentation](https://logging.apache.org/log4net/release/manual/configuration.html) gives an example using `XmlConfigurator`: > using log4net; > using log4net.Config; > > public class MyApp > { > private static readonly ILog log = LogManager.GetLogger(typeof(MyApp)); > > static void Main(string[] args) > { > // BasicConfigurator replaced with XmlConfigurator. > XmlConfigurator.Configure(new System.IO.FileInfo(args[0])); > > log.Info("Entering application."); > Bar bar = new Bar(); > bar.DoIt(); > log.Info("Exiting application."); > } > } In this example the filename is passed from the command line, but you can easily replace that. If what you dislike is specifically the XML, there's probably some way of mashing it up with [Newtonsoft's JSON.Net](https://www.newtonsoft.com/json/help/html/ConvertingJSONandXML.htm) to turn a JSON file into an `XElement` and pass that to the alternative `XmlConfigurator.Configure` method.