Skip to main content

Introduction to Log4Net

Log4net

Log4net (http://logging.apache.org/log4net/) is a tool to help the programmer output log statements to a variety of output targets, i have used it handling all the logging requirements of the applications that i have developed recently. And have found it integrates very well with spring.net and NHibernate.

In most cases i have set up the apps to log everything to a file and also log errors/warnings to an SMTP logger (which effectively sends an email out to me).
There are loads of examples and manuals etc on the website http://logging.apache.org/log4net/ it gives loads of good config examples too.

In order to get log4net working all you need is the log4net dll, configuration, and a small amount of code to get it started and logging. (this page is a good read http://logging.apache.org/log4net/release/manual/configuration.html)

But the minimum to take away is:
1. Reference the log4net dll
2. Import the log4net classes
2.1. using log4net;
2.2. using log4net.Config;
3. Add a config file (usually just a section to your web.config or app.config)
4. Add a call to the configurator
4.1. log4net.Config.XmlConfigurator?.Configure();
4.2. Or [assembly: log4net.Config.XmlConfigurator?(Watch=true)]
5. Create a logger
5.1. private static readonly ILog log = LogManager?.GetLogger?(typeof(MyClassName?));
5.2. each class should have its own logger, which should be private and static (log4net is thread safe)
6. Use the logger to log
6.1. log.Info("my info message.");

TIP
If you find you are getting double entries for log records it is probably due to you having duplicated entries in the log config. For example you might have the root set to debug logging and a named logger also set to debug, which will mean that 2 log entries get inserted for all debug messages from that named logger.

Facebook

Facebook Recommendations

Followers


Web Designing In Karachi



Haroof.com


Politics blogs

My Zimbio

Email Subscribe

Enter your email address:

Watch online Live TV

Popular posts from this blog

BRITISH FIRM TO INTRODUCE DISSOLVABLE POLYTHENE BAGS IN KARACHI.

CNews Karachi. July 05: A Pakistani Scientist in Britain has invented a new chemical for processing plastic (polythene) bags which has the quality of dissolution after its use in 105 days.A manufacturing unit for these plastic bags was being set up in Turkey while interest has been shown in the setting up of a big unit and manufacturing firm’s head quarter in Karachi which will be used to supply such dissolvable polythene bags to Asian countries. The Director of UK based firm Bio Plast Biodegradable Plastics GL Punn while leading a 15 member delegation called on EDO Municipal Services City Government Masood Alam. The Executive Director of Bio Plast Pakistan Muhammad Hanif Awan and M. Sultan Mehmood Awan was also present on this occasion. The Director of Bio Plast informed the EDO Municipal Services about the characteristics of new chemical. He said that the firm was going to set up its first plant in Turkey which will be operative in next two months. The delegation also praised the vi

Admission Open in Class XI in Pre-Engineering, Pre-Medical, and Commerce Groups at BODMAS MODEL COLLEGE, North Nazimabad, Karachi

  Admission Open in Class XI in Pre-Engineering, Pre-Medical, and Commerce Groups at BODMAS MODEL COLLEGE, North Nazimabad, Karachi.

Matric General Group Result SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X - 2010 (www.apnieyesp.com )

PASSED THE SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X) ANNUAL EXAMINATION, 2010. ERRORS AND OMISSIONS EXCEPTED, CANDIDATES BEARING THE FOLLOWING ROLL NUMBERS ARE DECLARED TO HAVE PASSED THE SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X) ANNUAL EXAMINATION, 2010. ------------------------------------------------- GENERAL GROUP (REG&PVT) --- GRADE..'A-ONE' ---- ----------------------- ( CANDIDATES SECURING TOTAL MARKS 680 AND ABOVE) MARKS SECURED BY THE CANDIDATES OUT OF TOTAL MARKS OF 850 ARE MENTIONED AGAINST EACH ROLL NUMBER IN BRACKET --------------------------------------------------- 601086 (689) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) 601327 (681) 363 (684) 364 (719) 407 (685) 664 (682) 788 (687) 601836 (692) 882 (683) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) 602315 (723) 316 (715) 320 (712) 321 (739) 325 (686) 326 (702) 602327 (683) 329 (70

Labels

Show more