log4net: -
Apache library used to track the status, error
and code execution level of your program.It can be used in asp.net and php.
There are different logging levels like: -1. OFF - nothing gets logged (cannot be called)
2. FATAL
3. ERROR
4. WARN
5. INFO
6. DEBUG
7. ALL - everything gets logged (cannot be
called)
Here I am going to use in ASP.net.
STEPS to implement: -1.
Install log4net from NuGet Package Manager.2.
Now Set configuration in web.config if you are
using web application or if using windows or console application set your
configuration in app.config.3.
Write this simple code above your namespace of
the class in which you are going to use like:-[assembly:log4net.Config.XmlConfigurator(Watch
=true)]
1:- To Install log4net:-
2. set configuraton in web.config
here i am using appender: FileAppender you can use other appender as well.
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net"/>
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="D:\log.log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %type.%method -
%message%n" />
</layout>
</appender>
<root>
<level value="All"/>
<appender-ref ref="FileAppender" />
</root>
</log4net>
3. Write Code like:-
[assembly:log4net.Config.XmlConfigurator(Watch =true)]
namespace WebScraping.Scriping
{
public class Scrap
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Scrap(string url)
{
log.Error(new Exception("Testing"));
}
}
finally you would get the file generated in you D drive which i have set in web.config.
to get more detail please visit:-
No comments:
Post a Comment