Configure log4Net for or

  1. Download log4Net from apache
  2. Add log4Net.dll to your project reference
  3. Add following code to web.config under tab
            <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
            <!--Root Logger is for all logger-->
                <level value="ALL" />
                <appender-ref ref="FileAppender" />
            </root> -->
            <logger name="FileAppender">
                <level value="ALL" /> Check all the level
                <appender-ref ref=" FileAppender " />
            <appender name=" FileAppender " type="log4net.Appender.RollingFileAppender">
                <file value="[Your directory and file name where you want to store log like ‘C:/Temp/app.log’]" />
                <appendToFile value="true" />
                <rollingStyle value="Composite" />
                <datePattern value="yyyyMMdd" />
                <maxSizeRollBackups value="10" />
                <maximumFileSize value="200K" />
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%date [%thread] - [%logger] %message%newline" />

    FileAppender is the name of the logger class, all logger with the name FileAppender will follow this configuration.
    *file value set the store path of the log file.

  4. Create a Logger class

    Imports log4net
    Public Class Logger
        Private Shared logger As ILog = LogManager.GetLogger("FileAppender")
        Public Shared Sub LogInfo(ByVal str As String)
        End Sub
        Public Shared Sub LogError(ByVal str As String)
        End Sub
        Public Shared Sub LogFatal(ByVal str As String)
        End Sub
    End Class


    using log4net;
    public class Logger
    private static ILog logger = LogManager.GetLogger("FileAppender");
    	public static void LogInfo(string str)
    	public static void LogError(string str)
    	public static void LogFatal(string str)
  5. Import the Logger class to your class and use it anywhere in your project

I will add the sample project for this soon.

2 thoughts on “Configure log4Net for or

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s