Enterprise Library step by step series (14th): Create asynchronous logs Based on Message Queue (MSMQ)

Source: Internet
Author: User
Tags msmq

Create a Message Queue (MSMQ).

I. Overview

In Enterprise Library step by step We have said in the series, Logs and detection applicationsProgramBlock Mainly2Components:ClientAndDistributor.ClientCreates a message.DistributorWrite destination location. Client According to the distribution policy (Distribution strategies) Send messagesDistributor, InApplication BlockProvided2Distribution Policies:In ProcessAndMSMQ, The default value isIn ProcessPolicy. Log synchronization is performed onClientWhile asynchronous logs useMSMQTo achieve,ClientYou need to create a log message and send itMSMQMessage queue. The other process waits for the message to arrive and writes it to the appropriate log receiving pool.

The application block containsWindows Service: MSMQ distributor Service. After the service is installed, the Service detects message queues at specified intervals.

Let's take a look at the log and Monitoring Application Block Processing flowchart:


Ii. install and configureMSMQ distributor Service

1. OpenVisual StudioCommand line tool, switch to the directory (the default installation path of the Enterprise Library)C: \ Program Files \ Microsoft Enterprise Library \ binRun the following command:

Installutil / I msmqdistributor.exe

Note: You must install the service in this way. Otherwise, the installation will fail.

2During the installation process, a set service Login Dialog Box is displayed, requiring you to enter the user name and password. In this case, the user name and password must be entered in the form of a domain user.<. \ USERNAME>The format is also possible, as shown in:


3. Start the service. In the Service Manager, findEnterprise Library logging distributor ServiceStart this service manually.


4. Open in a text editorMsmqdistributor.exe. configFile, delete the following section:

< Configurationsections >
< Configurationsection Name = "Loggingconfiguration" Encrypt = "False" >
< Storageprovider Xsi: Type = "Xmlfilestorageproviderdata" Name = "XML file storage provider" Path = "Loggingconfiguration. config"   />
< Datatransformer Xsi: Type = "Xmlserializertransformerdata" Name = "XML serializer transformer" >
< Includetypes />
</ Datatransformer >
</ Configurationsection >

5. UseConfiguration console,OpenMsmqdistributor.exe. configFile

SetMSMQ distributor ServiceAddDistributor settings, As shown in:


6. SetMsmqpathProperty MatchingClientQueue name, which can be modifiedMsmqpathBut the value must be consistent withClientThe configurations are consistent.


Iii. UseMSMQCreate asynchronous log

1. As we mentioned earlier,Client settingsDetermine the distribution policy,OneClientUse the same policy for all messages. Therefore, we cannot create two policies at the same time. We must delete them first.In ProcessBefore creatingMSMQ:


2. CreateMSMQAfter the distribution policy, note that the queue name must be consistent with what we mentioned in Section 2:


3.Enterprise Library step by stepThe same is written in the series.

For more information, see:

Enterprise Library step by stepSeries (7): logging and monitoring application blocks--Entry

Enterprise Library step by stepSeries (8): logging and monitoring application blocks--Advanced

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.