MSMQ Trace Listener get Messages from queue

Topics: Logging Application Block
Jul 11, 2014 at 8:20 AM
can i write queue messages into text file or log file?

pls help me.....
Jul 15, 2014 at 5:37 AM
Yes, you can direct queued LogEntry's to any trace listener. It is just a matter of configuring the loggingConfiguration in the MsmqDistributor.exe.config with the appropriate settings. For example:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
        <section name="msmqDistributorSettings" type="Microsoft.Practices.EnterpriseLibrary.Logging.MsmqDistributor.Configuration.MsmqDistributorSettings, MsmqDistributor"/>
    </configSections>
    <loggingConfiguration tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <logFilters/>
        <categorySources>
            <add
                name="General"
                switchValue="All">
                <listeners>
                    <add name="Flat File Trace Listener"/>
                    <add name="Formatted EventLog TraceListener"/>
                </listeners>
            </add>
        </categorySources>  
        <specialSources>
            <errors name="errors" switchValue="All">
                <listeners>
                    <add name="Formatted EventLog TraceListener"/>
                </listeners>
            </errors>
            <allEvents name="allEvents" switchValue="All">
                <listeners/>
            </allEvents>
            <notProcessed name="notProcessed" switchValue="All">
                <listeners/>
            </notProcessed>
        </specialSources>
        <listeners>
            <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
                fileName="trace.log" formatter="Text Formatter" />
            <add name="Formatted EventLog TraceListener" 
                type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" 
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" 
                source="Enterprise Library Logging" 
                formatter="Text Formatter"/>
        </listeners>
        <formatters>
            <add
                name="Text Formatter"
                type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
                template="Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {machine}{newline}App Domain: {appDomain}{newline}ProcessId: {processId}{newline}Process Name: {processName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}" />
        </formatters>
    </loggingConfiguration>
    <msmqDistributorSettings
        msmqPath=".\Private$\entlib"
        queueTimerInterval="1000" 
        serviceName="Enterprise Library Distributor Service" />
</configuration>
See Using the Distributor Service for more information about the Distributor Service.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to