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.
Here are the steps to get started with log4net:
- Download NAnt, the free .NET build tool.
- Extract the contents of the archive to the location you wish to install C:\Program Files\NAnt
- Edit log4net-1.2.10 build.cmd file. Remove nant-0.85-nightly-2006-03-06 from line 21.
- Run the SN utility from the .NET Framework SDK as follows: sn -k log4net.snk
- Copy log4net.snk to log4net-1.2.10 directory
- Run build.cmd from command line
- Copy log4net.dll and log4net.xml files from log4net-1.2.10\bin\net\1.1\release to bin directory
- 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!
- Add section to web.config
- Add Reference to log4net
- Add classes to Imports
- Declare a logger object
Private Shared ReadOnly log As ILog = LogManager.GetLogger(GetType(WebForm1))
- 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.”)
- Make sure the web root has write permissions for ASPNET network account
- Add line of code to global.asa.vb file in Sub Application_Start. Make sure to include Imports log4net in global.asa.vb
- 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.