Log4net does not write the log in the log file

后端 未结 13 2306
一生所求
一生所求 2020-11-29 17:09

I have created a simple scenario using Log4net, but it seems that my log appenders do not work because the messages are not added to the log file.

I added the followi

相关标签:
13条回答
  • 2020-11-29 17:53

    As @AndreasPaulsson suggested, we need to configure it. I am doing the configuration in AssemblyInfo file. I specify the configuration file name here.

    // Log4Net Configuration.
    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
    
    0 讨论(0)
  • 2020-11-29 17:55

    Make sure the process (account) that the site is running under has privileges to write to the output directory.

    In IIS 7 and above this is configured on the application pool and is normally the AppPool Identity, which will not normally have permission to write to all directories.

    Check your event logs (application and security) to see if any exceptions were thrown.

    0 讨论(0)
  • 2020-11-29 17:55

    In my case I had to give the IIS_IUSRS Read\write permission to the log file.

    0 讨论(0)
  • 2020-11-29 17:55

    There are a few ways to use log4net. I found it is useful while I was searching for a solution. The solution is described here: https://www.hemelix.com/log4net/

    0 讨论(0)
  • 2020-11-29 17:56

    Do you call

    log4net.Config.XmlConfigurator.Configure();
    

    somewhere to make log4net read your configuration? E.g. in Global.asax:

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
    
        // Initialize log4net.
        log4net.Config.XmlConfigurator.Configure();
    }
    
    0 讨论(0)
  • 2020-11-29 18:00

    For me I had to move Logger to a Nuget Package. Below code need to be added in NuGet package project.

    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]
    

    See https://gurunadhduvvuru.wordpress.com/2020/04/30/log4net-issues-when-moved-it-to-a-nuget-package/ for more details.

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