A small discovery in the Enterprise Library

Source: Internet
Author: User

It has been plagued by several problems in the enterprise database:
1. After the enterprise database is used, there will always be a bunch of errors in the event log, and I don't know how to solve them. Besides affecting log reading, there are no other problems.
Failed to create instances of performance counter 'average Command Execution time'-the requested performance counter is not a custom counter and must be initialized as read-only ..
2. In the block of Logging & instrumentation application block, it seems that only one logging is used for usage. It seems that there has never been anything about instrumentation. In addition, it seems that there has never been a concept of dashboard, I don't know what it is for (including those I didn't seem to mention in the webcast Lecture), so I 've been using it as a logging Application Block.
3. What is instrumentation in the enterprise database and its purpose?

However, these problems have no harm to the entire application, so I have never been able to manage it. I have been reading the code of the enterprise database some time ago, So I suddenly realized that these problems are a problem.

EventLog in logging may be familiar to everyone. Even if you do not need an Enterprise Library, you can use the classes in the system. Diagnostics namespace. In fact, instrumentation should be performancecounter. Performance counters ??? By the way, there is a "performance" system tool in the management tool. You should have used it to track CPU and memory ...... this is a commonly used tool for stress testing.
We all want to use EventLog for trace, but have you ever thought about using performance counters to track our programs. Tracking what ??? For example, the number of SQL command executions, execution time, and number of exceptions, and the performance counters can be displayed graphically.
Is it difficult to do this ??? It is very simple to use the counters of the enterprise database.
In fact, the enterprise database has a built-in custom performancecounter. The problem 1 is that the counter is not registered. How to register ?? There are two methods:
1. Run installservices. bat, copy the batch to your Enterprise Library dll Directory, and run registration.
2. If you have created your installer and packaged the Enterprise Library file in your package, the Enterprise Library can automatically register the performance counter (see the Enterprise Library has implemented related classes, but I have never done any tests. If you are interested, you can try it)

Now, we can see the following results:

The red warning in Event Log is eliminated, and a new function is added. Haha, do stress testing plan ??? It is easy to use !!

Not enough. I still want to do it myself. Sorry, I just took a look at it and shared with you what I saw. Some experts did not give more comments.
There are two key performance counters: performancecounter and performancecounterinstaller.
Performancecounter is a real counter. You can look for several examples in the enterprise database to see its implementation.

Performancecounterinstaller is responsible for the installation and registration of counters, in the Enterprise Library (take 2.0 as an example) Common. instrumentation. common. reflectioninstaller is responsible for finding performancecounterinstaller in reflection mode, such as data. instrumentation. in datainstrumentationinstaller
Installers. Add (New reflectioninstaller <performancecounterinstallerbuilder> ());
You can register performancecounterinstallerto the installer, and register and install it by the installer or installutil.exe.

If it is not clear, let's take a look at a very simple example in the unit test: Microsoft. Practices. enterpriselibrary. Common. instrumentation. Tests. perfcounterinstaller. The Code will not be pasted.

In other words, the ephemeral disk is also unavailable, and mshas been released to allow users to enable or disable the configuration in entlibconfig.exe (not tested yet), which is also a major improvement

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.