Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net does not write the log in the log file

People also ask

Where do log4net logs go?

In your case, the log file will be in bin\Debug\netcoreapp3.

Is log4net structured logging?

log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.


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();
}

Use this FAQ page: Apache log4net Frequently Asked Questions

About 3/4 of the way down it tells you how to enable log4net debugging by using application tracing. This will tell you where your issue is.

The basics are:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
</configuration>

And you see the trace in the standard output


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)]

Also, Make sure the "Copy always" option is selected for [log4net].config

enter image description here