I don’t know about you folks but my memory is quite lousy. At
the ripe age of 26, it’s not as good as its use to be and hence I usually end
up looking things up like when trying to use Log4NET. My favorite destination
is either the Apache website or Nauman’s
Log4NET. So here is a simple five step process of adding logging to an
application. For times when MS logging app block seems like overkill and
console writing to a text file is not an option, Log4NET is the way to go.
So without further ado
Step 1. Add the following at the top of the application
config file. This tells the config engine that there is a Log4NET section
<?xml version="1.0" encoding="utf-8" ?>
2. Add the following before/after appsettings.
name="ConversionPattern" value="%r %d [%t] %-5p %c -
Step 3. Add the following in the AssemblyInfo.cs
ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Step 5. Add the following line in the code where you want
logging to be done.
log.Info("Program Started "
+ DateTime.Now.ToString ());
This will log the info in the MyLogFile in the log folder.
The above steps provide a cookie cutter recipe for jump
start using Log4NET. For further information about what the above config
sections actually mean, please see the following reference articles below.