0

My log4net configuration is stored in a config file located in a subdirectory of the application root.

Config\logging.config

The file is marked as an application content with attribute "Copy Always". Additionaly, in my AssemblyInfo.cs, I've declared the following line:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Config\\logging.config", Watch = true)]

However, log4net doesn't log anything and it doesn't look like its initialized. How can I tell log4net where my configuration file is so it can initialize its components correctly?

Acrotygma
  • 2,531
  • 3
  • 27
  • 54
  • From documentation: 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. – Mihai Hantea Mar 04 '14 at 01:13
  • @MihaiHantea Yes, LogManager.GetLogger is being called prior to everything else through a LogFactory. – Acrotygma Mar 04 '14 at 01:20
  • I just check it and works fine even is the config file is in a subdirectory, also you need to have permission to write to file if you are using this type of appender, try placing a logger in the same class that starts your application (program.cs, app.xaml, whatever). – Mihai Hantea Mar 04 '14 at 01:33

1 Answers1

2

Log4Net is designed to fail silently, on the grounds that no logging is preferable to taking down the application.

Most problems with log4net are (in my experience) related to file and permissions issues.

  • Does the account under which your app runs have read access to the entire path to the config file?

  • Is the "current working directory" what you think it is at the time the log4net config file is loaded?

To find out what the underlying problem is, use log4net's internall debugging:

Community
  • 1
  • 1
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135