log4net initialisation

前端 未结 1 788
陌清茗
陌清茗 2020-12-06 04:21

I\'ve looked hard for duplicates but have to ask the following, no matter how basic it may seem, to get it clear once and for all!

In a fresh Console app using log4n

相关标签:
1条回答
  • 2020-12-06 04:40

    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.

    0 讨论(0)
提交回复
热议问题