log4net initialisation

纵饮孤独 提交于 2019-11-27 22:43:12

According to the configuration page in the manual:

The log4net configuration can be configured using assembly-level attributes rather than specified programmatically.

XmlConfiguratorAttribute: The log4net.Config.XmlConfiguratorAttribute Allows the XmlConfigurator to be configured using the following properties:

  • ConfigFile ...
  • ConfigFileExtension ...

If neither of the ConfigFile or ConfigFileExtension properties are specified, the application configuration file (e.g. TestApp.exe.config) will be used as the log4net configuration file.

Example usage:

// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.

I agree that it's a bit ambiguous, but I interpret the existence of the example usage to mean that log4net will not use the .config file without the above attribute; and the fact that they point out that you have to use one of the two properties, but do not say anything about leaving out the attribute altogether, suggests to me that the attribute (or programmatic call) is required to use app.config in the way you want.

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