Log4Net for C #
by Jose Jorge Marquez Gomez on ago.25, 2010, under DoNet
Well today I'll tell you a little how to configure log4net for c #. But before I tell you that is log4net.
Log4Net is a framework log4java ported the library, which provides all the tools possible to make a logging, error handling, monitoring all your applications for possible applications. In my view, the log is as good as I've tried so far and is quite easy to configure. Offers several monitoring modes and even create you your own. That bookstore you can get http://logging.apache.org/log4net/index.html .
Explain some concepts related to log4net.
Log4Net offers multiple levels of monitoring predefined as:
1. Debug: This is usually used for debug lines.
2. Info: It is often used to give information relating to your application.
3. Warn: breakpoints are possible of your software, I mean, any important alerts.
4. Error: Used to detect errors in your software.
5. Fatal is used to detect significant errors in software, ie to prevent the operation thereof for example.
These levels are predefined brings log4net, but you can create custom levels.
Another highlight is the appenders, this is just how different levels of log4net will be monitored / logged in log4net there these include:
1. FileAppender: logs on the level defined in the configuration file.
2. RollingFileAppender: logs on the level defined in the configuration in a file that rotates depending on their weight.
3. SmtpAppender: logs on the level defined in the configuration and is sent to a mail recipient.
Later on you will see an example of setting these levels configured. For details of all properties you can see the web appenders you have below.
All you can see detailed on this web http://logging.apache.org/log4net/release/config-examples.html .
Begin.
The first step is descargaros library the previous website, once downloaded, you must add this library to your project references. Then we'll set the log4net in the configuration file of your application, if a Web application is the web.config, if the app.config console application, etc ...
In the tag "configuration" -> "ConfigSection" -> agregad the following line:
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/> Then a new tag that we called "<log4net>" the appenders are configured there. Each has its own settings in the previous website you can see all. Deputy log4net Example
Once we have this, you already use our log4net in your application. A requirement to be met is that each class must initialize log4net in its constructor so that it is as illustrated in the following code:
class test { Ilog private log; public test () { log4net.Config.XmlConfigurator.Configure (); log = LogManager.GetLogger (this.GetType ()) / / here we proceed to initialize the object log. }
To make use of our log is simple, we just call the different levels of alert that has through the object log.
I hope you serve as a seed with log4net.
Greetings!






