Configure log4net to MS SQL under ASP.NET.

zhaozj2021-02-17  31

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

......

->

->

Special instructions , this is the buffer size of the log information record, (such as only the log information record reaches 10,

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.

///

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

转载请注明原文地址:https://www.9cbs.com/read-29015.html

New Post(0)