Log4Net not working for console app

家住魔仙堡 提交于 2019-12-13 00:35:13

问题


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?


回答1:


  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


来源:https://stackoverflow.com/questions/26557067/log4net-not-working-for-console-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!