Simple Example For Log4Net Dll How To Use…. IN Asp.net

Global.asax

void Application_Start(object sender, EventArgs e)
{
log4net.Config.DOMConfigurator.Configure();

}

Default.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using log4net.Config;

public partial class _Default : System.Web.UI.Page
{
ILog logger = log4net.LogManager.GetLogger(typeof(_Default));

protected void Page_Load(object sender, EventArgs e)
{
logger.Info(“Hello Nine Thanks for use Log4Net,This is info message”);
logger.Debug(“Hello Nine Thanks for use Log4Net,This is Debug message”);
logger.Error(“Hello Nine Thanks for use Log4Net,This is Error message”);
logger.Warn(“Hello Nine Thanks for use Log4Net,This is Warn message”);
logger.Fatal(“Hello Nine Thanks for use Log4Net,This is Fatal message”);

}
}


Web.Config File


</system.web>
    <log4net>
        <appender name=”FileAppender” type=”log4net.Appender.FileAppender”>
            <param name=”File” value=”D:\\Users\\Tushar\\MyloggerSite.log”/>
            <!– Example using environment variables in params –>
            <!– <param name=”File” value=”${TMP}\\ApplicationKit.log” /> –>
            <param name=”AppendToFile” value=”true”/>
            <layout type=”log4net.Layout.PatternLayout”>
                <param name=”ConversionPattern” value=”%d [%t] %-2p %c [%x] – %m%n”/>
        <!–<param name=”ConversionPattern” value=”%date [%thread] %-5level %logger [%ndc] – %message%newline” />–>
            </layout>
        </appender>
        <root>
            <level value=”ALL”/>
            <appender-ref ref=”FileAppender”/>
        </root>
    </log4net>

<system.codedom>

Advertisements

2 thoughts on “Simple Example For Log4Net Dll How To Use…. IN Asp.net”

  1. Hello! I know this is kind of off topic but I was wondering which blog platform are you using for this site?
    I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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