Log4net is an excellent open source log project, which is now written as a Demo, as follows
0: Preparation
Go to http://logging.apache.org/, you can download log4net, the latest version 1.2,
Create an ASP.NET web project and add log4net.dll to reference
1: Establish a data sheet
Create Table [DBO]. [Log] (
[ID] [INT] Identity (1, 1) Not NULL,
[DATE] [datetime] not null,
[Thread] [varchar] (255) Not null,
[Level] [varchar] (50) Not null,
[Logger] [varchar] (255) Not null,
[Message] [varchar] (4000) Not null,
[EXception] [varchar] NULL
)
2: Write a configuration file
configsections>
......
->
root>
logger>
->
parameter>
layout>
parameter>
layout>
parameter>
layout>
parameter>
layout>
parameter>
parameter>
appender>
log4net> configuration>
Special instructions
Write log information to the database
3: in Global.asax.cs
Protected void Application_Start (Object Sender, Eventargs E)
{
// Read configuration information
Log4net.config.domconfigurator.configure ();
}
4: A Demo class that uses log
Using system;
Namespace log
{
///
/// MYLOG summary description.
/// summary>
Public class mylog
{
Private static readonly log4net.ilog log = log4net.logmanager.getlogger (Typlace);
Public static void loginfo ()
{
Log.info ("Log Log");
}
Public static void logerror ()
{
LOG.INFO ("Log Error");
}
}
}
5: Resources:
My blog: http://tomch.donews.net/tomCh/posts/22457.aspx
Main site
Logging.apache.org/
Learn articles using Log4Net
Www.ondotnet.com/pub/a/dotnet/2003/06/16/log4net.html
2472-log.rar