C # error logging tool,

Source: Internet
Author: User

C # error logging tool,

During programming, we often use try... catch to process code blocks that may encounter errors. If an error occurs in the program, the error message is displayed.

Of course, a large system has an error log processing module, which uses a database to record error log information, and has the function of writing error logs and reading operation logs. It has powerful functions, implementation is certainly quite complicated.

Sometimes we just want to conveniently view the error log information, but do not want to bring complicated code implementation. What do fish and bear's paw want? Okay, let me meet you.

1. We need to set the target Framework of the Project to. Net Framework 4.0;

2. Find the code generation path of the project, such as bin \ Debug \. download the required DLL and configuration files from the link address, and copy the downloaded files to the code generation path;

3. Add a reference to BPM. Framework. Client. dll and NLog. dll in the project;

4. Compile the test program:

 

Using System; using System. collections. generic; using System. linq; using System. text; using BPM. framework. client; namespace Demo {class Program {static void Main (string [] args) {int intA = 10; int intB = 0; int intC; try {intC = intA/intB ;} catch (Exception ex) {LogInfo. writeLog (LogInfo. logLevel. info, "the divisor cannot be 0" + ex. message );}}}}

5. View error log information. Run the program. A logfolder is generated under the bin \ Degug \ directory, and a debug_date.html file is generated under the logfile. This file is used to record error logs. For example, the error information of the above program is as follows:

 

At this point, the functions and usage of the tool have been described, and we hope to help you easily record error logs.

Related Article

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.