简体   繁体   中英

How to add logging to Windows Event Log using system.diagnostics

I created custom WCF LOB Adapter. And I'm using Trace class in it. I would like BizTalk server to write log from that adapter to Windows Event Log.

When I add below section to BizTalk host config file BizTalk doesn't start. What is wrong with it?

<system.diagnostics>
  <trace autoflush="true">
  <sources>  
    <source name="AzureServiceBusClient" switchValue="Verbose, ActivityTracing">  
      <listeners>  
        <add name="AzureServiceBusTraceListener" />  
      </listeners>  
    </source>  
  </sources>  
    <sharedListeners>
      <add name="AzureServiceBusTraceListener" type="System.Diagnostics.EventLogTraceListener" initializeData="BizTalk Server" />       
    </sharedListeners>
</trace>
</system.diagnostics>

This is how my trace class is created in code:

//
// Initializes a new instane of  Microsoft.ServiceModel.Channels.Common.AdapterTrace using the specified name for the source
//
static AdapterTrace trace = new AdapterTrace("AzureServiceBusClient");

The sources should be a separate item to the trace, rather than nested as you have them. I think you must have forgotten to self terminate the trace tag, and then added the end tag in, making it invalid.

Correcting it to the below should hopefully fix your BizTalk not starting.

<system.diagnostics>
    <trace autoflush="true" />
    <sources>  
        <source name="AzureServiceBusClient" switchValue="Verbose, ActivityTracing">  
            <listeners>  
                <add name="AzureServiceBusTraceListener" />  
            </listeners>  
        </source>  
    </sources>  
    <sharedListeners>
        <add name="AzureServiceBusTraceListener" type="System.Diagnostics.EventLogTraceListener" initializeData="BizTalk Server" />       
    </sharedListeners>
</system.diagnostics>

Below example from Diagnostic Tracing and Message Logging

<system.diagnostics>
    <sources>
      <source name ="System.ServiceModel" switchValue="Verbose">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name ="System.ServiceModel.MessageLogging" 
              switchValue="Verbose, ActivityTracing">        
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name ="System.Runtime.Serialization" switchValue="Verbose">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
   </sources>
   <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener"              
           traceOutputOptions="LogicalOperationStack" 
           initializeData="C:\log\WCFTrace.svclog" />
   </sharedListeners>
   <trace autoflush="true" />
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging 
           logEntireMessage="true" 
           logMalformedMessages="false"
           logMessagesAtServiceLevel="true" 
           logMessagesAtTransportLevel="false"/>
    </diagnostics>    
  </system.serviceModel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM