.net - How to initialize log4net GlobalContext properties in configuration file -


is there way define global context property in configuration file if don't want set in code like

log4net.globalcontext.properties["appname"] = "mycoolapp"; 

?

log4net not provide functionality, can build yourself:

  • store key / value pairs in configuration file of choice
  • read key value pairs on start , assign global context

the second part this:

dictionary<string, string> pairs = readglobalcontextconfiguration(); foreach (var pair in pairs) {     log4net.globalcontext.properties[pair.key] = pair.value; } 

the first part depends on want store information. there many options:

  • configuration section in app/web.config
  • simple xml file
  • simple text file key=value entries per line

Comments