Showing posts with label .net core. Show all posts
Showing posts with label .net core. Show all posts

Tuesday, 29 October 2019

Tuesday, 5 March 2019

.net core console adding log4net


Log4Net will not use the log settings in the appsetting.json file, it needs a log4net.config file 😭


  • add package



  • add config file

  • ensure it is set to copy to output directory

  • update config in file as required

  • add Log4Net into the logging framework

  • get logger via dependancy injection as per standard

Monday, 4 March 2019

.net core making config accessible to all classes


in .net framework ConfigurationManager could be accessed anywhere. The .net core method of accessing configuration requires some setup, so rather than doing that on every class set it up once and add it to the services so can be accessed via dependancy injection.


* in the startup method get a IConfigurationRoot based on the config file


* add the IConfigurationRoot object to the services collection


* in a class that needs to access configuration, get a concrete class via DI
Save the value into a private var accessible to the entire class.

* Any code in the class can access config via the private var