john84 john84 - 2 months ago 19x
ASP.NET (C#) Question

Log4net does not write the log file

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

I added the following to the web.config file:

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

<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="D:\MyData\Desktop\LogFile.txt" />
<appendToFile value="true" />
<encoding value="utf-8" />
<layout type="log4net.Layout.SimpleLayout" />

<level value="INFO" />
<appender-ref ref="LogFileAppender" />

Within the global ASAX file I added:

ILog logger = LogManager.GetLogger(typeof(MvcApplication));

and within the Application_Start method:

logger.Info("Starting the application...");

What did I do wrong?

Thanks in advance


Do you call


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.