Now that we have all the key pieces of our application in place, let's add some logging information to our Ordering.Console application to give us some information about what's going on inside.
The first thing we need to do is add a
using
orImports
statement to the main class of our application.using log4net;
And in VB.NET:
Imports log4net;
Next, let's add a new logger to the class so that we can add logging messages. Inside the class or module, add the following code to get a local instance of the logger:
private static ILog log = LogManager.GetLogger(typeof(Program));
Once again in VB.NET:
Private log As ILog = LogManager.GetLogger(GetType(Module1))
Now we're ready to log some data. Let's start out by adding some simple instrumentation timings. Let's find out how long it's taking us to configure NHibernate.
Under the line
log4net.Config.XmlConfigurator.Configure()
, let's add a start time to base our timings on:Stopwatch sw = Stopwatch.StartNew();
The...