When I wanted to add some logging to my web applications I looked at the various solutions that were already available. Many people have recommended Log4Net so I gave it a look. Overall the solution is very deep and customizable but can be a little trying if you are unfamiliar with the configuration.
Now I know there are several posts from other bloggers that contains sample applications but all of the ones I tried didn’t work. So at the risk of adding more duplicate content to the internet, and after spending several hours learning about adding Log4Net to my web applications, I decided to post a template website.
This template site provides all you need to know in order to get Log4Net working on your web application. You can simply extract the zip folder and point IIS to the folder. About the only thing you might need to change is the location (default is the ~/app_data folder) to wherever you would prefer.
Some interesting points about this template.
- Configuration is stored in a separate log4net.config file instead of storing the data in the web.config file.
- Includes both an Eventlog and Rollinglogfile appender for the choice to log in multiple places
- The log filename used by the RollingLogFile appender is dynamically set to the app name
- The application name used by the Eventlog appender is dynamically set to the app name
- The logger name is configured dynamically to be the class name.
- Unhandled exceptions are included in the default logging configuration
So the next time you are starting a new web application you might consider using the attached website template as a launching point.




Kim Cameron's Identity Weblog
Sat, Feb 21, 2009
Technology