Use log4net In the. net Website project to record logs to the sqlserver Database

Source: Internet
Author: User
1: First, you need to download the dll on the official website. This is not difficult: the official website is: logging. apache. orglog4net. After the download, use vs to compile and obtain log4net. dll. Introduce it into the project again and add reference. 2: add a line of code to the AssemblyInfo. cs file in the project to specify the search for Web. Co

1: first need to download dll on the official website, This is not difficult: the official website is: http://logging.apache.org/log4net/, download and use vs to compile get log4net. dll. Introduce it into the project again and add reference. 2: add a line of code to the AssemblyInfo. cs file in the project to specify the search for Web. Co

1: first need to download dll on the official website, This is not difficult: Official Website: http://logging.apache.org/log4net/, download afterUseVs compiled to obtain log4net. dll.

Introduce it againProjectProject, add reference.


2: Then setProjectAdd a line of code in the AssemblyInfo. cs file to specify the log4net configuration information in the Web. Config file:

[Assembly: log4net. Config. XmlConfigurator (ConfigFile = "Web. config", Watch = true)]

3: Start to configure the web. Config file:





Add the above Code Node.

4: Configure log4 output mode





































































Note: The SystemLog table here isDatabaseMust exist.

5. frontend interface call

Public partial class Index: System. Web. UI. Page

{

Private static log4net. ILog loger = log4net. logManager. getLogger (System. reflection. methodBase. getCurrentMethod (). declaringType); = log4net. logManager. getLogger (System. reflection. methodBase. getCurrentMethod (). declaringType );

Loger. Info ("TestRecordLogsToDatabase. ");

}

Note: System. Reflection. MethodBase. GetCurrentMethod (). DeclaringType indicates the callRecordLogsMethod class. For example, the above class is Index.

The above code can be written to any event.


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.