How do I configure log4net so that log.IsDebugEnabled is true?

后端 未结 6 448
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 02:51

I am trying to use log4net in an ASP.NET application with Visual Studio 2005. I have declared an instance of the logger like so:

Private Shared ReadOnly log          


        
相关标签:
6条回答
  • 2020-12-29 03:31

    Before calling LogManager.GetLogger("")

    You have to call log4net.Config.XmlConfigurator.Configure(); In an ASP.NET app you probably want to put this call in Application_Start

    0 讨论(0)
  • 2020-12-29 03:32

    If you are setting log4net up in code rather than in a config file, you can call log4net.Config.BasicConfigurator.Configure before GetLogger.

    0 讨论(0)
  • 2020-12-29 03:33

    Yes, do it like Anson said. Also, if you are calling Configure in a class library you can do that by adding an attribute to your class:

    [assembly: XmlConfigurator(Watch = true)]
    

    and if you're using log4net.config file, use it like that instead:

    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
    
    0 讨论(0)
  • 2020-12-29 03:33

    VB.NET -

    <Assembly: log4net.Config.XmlConfigurator(Watch:=True)> 
    
    0 讨论(0)
  • 2020-12-29 03:33

    Use this in any method before you use log :

    log4net.Config.XmlConfigurator.Configure();

    In App.Config ,the settings should be :

    <root>
          <level value="ALL" />
          <appender-ref ref="AppenderName" />
        </root>
    
    0 讨论(0)
  • 2020-12-29 03:35

    If you are using a separate configuration file for log4net, do this: after following all the other setup instructions, make sure that u right click on the file in the visual studio solution explorer, select properties, expand the "Advanced" option group, set the "Copy To Output Directory" value as "Copy always". That will do the magic... :) cheers!!

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