log4net With ASP.NET 1.1

log4net provides the same sort of debug and trace logging capabilities as the trace listeners in ASP.NET 2.0 but it can be used in ASP.NET 1.1. Therefore if you like trace listeners in ASP.NET 2.0 but have some ASP.NET 1.1 web applications that you cannot upgrade, you should give log4net a try.

The log4net web page can be found at: http://logging.apache.org/log4net/ You will also need the NAnt build tool from http://nant.sourceforge.net/

Here are the steps to get started with log4net:

  1. Download NAnt, the free .NET build tool.
  2. Extract the contents of the archive to the location you wish to install C:\Program Files\NAnt
  3. Edit log4net-1.2.10 build.cmd file. Remove nant-0.85-nightly-2006-03-06 from line 21.
  4. Run the SN utility from the .NET Framework SDK as follows: sn -k log4net.snk
  5. Copy log4net.snk to log4net-1.2.10 directory
  6. Run build.cmd from command line
  7. Copy log4net.dll and log4net.xml files from log4net-1.2.10\bin\net\1.1\release to bin directory
  8. Add configSection to web.config file. The version number is the most troublesome aspect. It may not be required or you may need to get the exact string from the output window error messages!
  9. Add section to web.config
  10. Add Reference to log4net
  11. Add classes to Imports
    Imports log4net
  12. Declare a logger object
    Private Shared ReadOnly log As ILog = LogManager.GetLogger(GetType(WebForm1))
  13. Add some Debug and Info statements to generate some output
    If log.IsDebugEnabled Then log.Debug(“Debug is enabled. Page_Load subroutine.”)
    If log.IsInfoEnabled Then log.Info(“Info is enabled. Page_Load subroutine.”)
  14. Make sure the web root has write permissions for ASPNET network account
  15. Add line of code to global.asa.vb file in Sub Application_Start. Make sure to include Imports log4net in global.asa.vb
  16. Add Assembly line to AssemblyInfo.vb <Assembly: log4net.Config.XmlConfigurator(ConfigFileExtension:=”log4net”, Watch:=True)>

log4net offers a few options that trace listeners don’t provide such as the ability to log trace and debug output to an Access database.

This entry was posted in ASP.NET. Bookmark the permalink.

Leave a Reply

Your email address will not be published.