How to configure Log4Net for your application

28 March 2022 | Viewed 1915 times

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary.

Follow below steps to configure and use Log4Net

1. Add log4net.dll to application references

2. Add configuration to web .cofig

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

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value=".\.\log\AppName-%property{LogName}.log" type="log4net.Util.PatternString"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="-yyyy-MM-dd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %C{1} - %m%n"/>

<level value="ALL"/>
<appender-ref ref="RollingLogFileAppender"/>

C# Code
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(

Hope this helps!