How to Implement log4net logs

Source: Internet
Author: User
Tags log4net

1. Introduction of log4net

Download and introduce log4net. dll in a web project

2. Place log4net. config in the root directory of the web project.

3. Add code in application_start of Global

Log4net. config. xmlconfigurator. configureandwatch (new system. Io. fileinfo (server. mappath ("~ /") +" Log4net. config "));

4. Declare and assign values to the base page class

For example, private ilog _ logger = NULL;
/// <Summary>
/// System Log Interface
/// </Summary>
Public ilog Logger
{
Get {return _ logger ;}
}

Protected override void onload (eventargs E)
{

_ Logger = logmanager. getlogger (this. GetType ());
Base. onload (E );
}

5. Use

Use logger directly on the page.

If there is no step 4, you can create and use it directly,

For example, logmanager. getlogger (this. GetType ());

Welcome to: http: // 121.18.78.216, which is a demonstration platform for ease of query and analysis, workflow, content management, and project management.

 

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.