Log4net doesn't write to file

后端 未结 4 1536
误落风尘
误落风尘 2020-12-17 20:28

I want add new log to file.this is my appender:



        
相关标签:
4条回答
  • 2020-12-17 20:55

    You need to initialise the logging as the very first step in your app, and from the same assembly that you have the [assembly] tag:

    From the docs:

    Therefore 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.

    Add something like this in your start up code:

    LogManager.GetLogger("Initialises logging from assembly attributes");
    
    0 讨论(0)
  • 2020-12-17 21:02

    Log4net fails silently when there's a problem. The design conceit is that no logging is preferable to taking down the application. To figure out what's wrong, turn on Log4net's internal debugging by adding this key to your [app/web].config file:

    <appSettings>
      <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
    

    The debug messages will be written to the console or to the System.Diagnostics.Trace system. More details from Phill Haack at http://haacked.com/archive/2006/09/26/Log4Net_Troubleshooting.aspx/

    There are any number of reasons Log4net might fail. Permissions problems on the log file directory, for starters (especially true for server processes, where your likely running under a restricted set of permissions for security).

    0 讨论(0)
  • 2020-12-17 21:02

    You should add this config section:

    <configSections>
    <section name="log4net"     type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    </configSections>
    

    to refer the log4net configuration.

    0 讨论(0)
  • 2020-12-17 21:11

    You just need to call Configure:

    log4net.Config.XmlConfigurator.Configure();
    

    You can see more details here: Log4net does not write the log file

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