1

I have a console app and I am trying to implement log4Net for it.

I did the following steps -

  1. added log4Net reference
  2. Created Log4Net.config -

    1. Created the LogHelper.cs class -

    2. Added the following to the AssemblyInfo.cs [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4net.config", Watch = true)]

But the logging doesnt seem to work? Can someone suggest what needs to be done for the logging to work in th console app?

SMV
  • 49
  • 1
  • 6

1 Answers1

5
  1. Make sure the config file is set to copy to the output directory.

  2. In the log4net documentation for assembly attributes it says:

".. if you use configuration attributes you must invoke log4net to allow it to read the attributes. A simple call to LogManager.GetLogger will cause the attributes on the calling assembly to be read and processed. Therefore it is imperative to make a logging call as early as possible during the application start-up, and certainly before any external assemblies have been loaded and invoked."

  1. If it still doesn't work, enable log4net debugging as in this answer
Community
  • 1
  • 1
stuartd
  • 70,509
  • 14
  • 132
  • 163