Log4NET
Step 1:
DownLoad log4net.dll
Step 2:
Add below entry in web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="e:\movieticket\log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<DatePattern value=".yyyyMMdd"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
</configuration>
Step 3:
using log4net;
using log4net.Config;
public partial class TestPage : System.Web.UI.Page
{
private static readonly ILog logger = LogManager.GetLogger(typeof(TestPage));
protected void Page_Load(object sender, EventArgs e)
{
DOMConfigurator.Configure();
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
logger.Debug("Here is a debug log.");
}
}
Step 4:
Download Viewer
For XML File Log:
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="E:\MovieTicket\log\BoxOffice.xml" />
<appendToFile value="true" />
<datePattern value="yyyyMMdd" />
<rollingStyle value="Date" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
<locationInfo value="true" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
1 comments:
Post a Comment