ASP.net log4net is an excellent open source log project, which I use to write a demo, as follows
0: Preparation
Go to http://logging.apache.org/, download log4net, latest version 1.2,
Create a ASP.net Web project and add Log4net.dll to the reference
1: Set up a data table
CREATE TABLE [dbo]. [Log] (
[ID] [int] IDENTITY (1, 1) not NULL,
[Date] [DateTime] Not NULL,
[Thread] [varchar] (255) Not NULL,
[Level] [varchar] () not NULL,
[Logger] [varchar] (255) Not NULL,
[Message] [varchar] (4000) Not NULL,
[Exception] [varchar] (Watts) NULL
)
Special note <buffersize value= "Ten"/>, this is the log information record of the buffer size (for example, only log information records up to 10,
Log information log will be written to the database)
3: In the 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
{
<summary>
Summary description of the mylog.
</summary>
public class MyLog
{
private static readonly log4net. ILog log = log4net. Logmanager.getlogger (typeof (MyLog));
public static void Loginfo ()
{
Log. Info ("log Logs");
}
public static void Logerror ()
{
Log. Info ("Log Error");
}
}
}
5: Resources:
My blog:http://tomch.donews.net/tomch/posts/22457.aspx
Master Station logging.apache.org/
Learn to use log4net articles www.ondotnet.com/pub/a/dotnet/2003/06/16/log4net.html
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.