Click here to Skip to main content
15,885,027 members
Articles / Programming Languages / C# 4.0

Common & Distributed Logging through Enterprise Library 5 (EntLib) Logging Application Block and MSMQ Distributor Service

Rate me:
Please Sign up or sign in to vote.
4.75/5 (10 votes)
12 Aug 2011CPOL16 min read 94.2K   2.2K   31  
About how to achieve a reliable and high performance logging through Logging Application Block and distributed logging through MSMQ Distributor Service.
<?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="Formatted EventLog TraceListener"/>
        </listeners>
      </add>
      <add
				name="Error"
				switchValue="All">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
          <add name="Flat File Trace Listener"/>
        </listeners>
      </add>
      <add
				name="None"
				switchValue="All">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
        </listeners>
      </add>
    </categorySources>

    <specialSources>
      <errors name="errors" switchValue="All">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
          <add name="Flat File Trace Listener"/>
        </listeners>
      </errors>
      <allEvents name="allEvents" switchValue="All">
        <listeners/>
      </allEvents>
      <notProcessed name="notProcessed" switchValue="All">
        <listeners/>
      </notProcessed>
    </specialSources>

    <listeners>
      <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"/>
      <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="C:\TraceTwo.log"
        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$\AnotherQ"
		queueTimerInterval="1000"
		serviceName="EntLibLoggingService" />
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Philips
India India
Have been working with computers since the early 00's. Since then I've been building, fixing, configuring, installing, coding and designing with them. At present I mainly code windows applications in C#, WCF, WPF and SQL. I'm very interested in Design Patterns and try and use these generic principles in all new projects to create truly n-tier architectures. Also I like to code for making the User Interface very attractive...

Comments and Discussions