SMV
SMV

Reputation: 49

Log4Net not working for console app

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?

Upvotes: 1

Views: 5567

Answers (1)

stuartd
stuartd

Reputation: 73243

  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

Upvotes: 5

Related Questions