简体   繁体   English

如何使用system.diagnostics将日志添加到Windows事件日志

[英]How to add logging to Windows Event Log using system.diagnostics

I created custom WCF LOB Adapter. 我创建了自定义WCF LOB适配器。 And I'm using Trace class in it. 我在其中使用Trace类。 I would like BizTalk server to write log from that adapter to Windows Event Log. 我希望BizTalk服务器将日志从该适配器写入Windows事件日志。

When I add below section to BizTalk host config file BizTalk doesn't start. 当我将以下部分添加到BizTalk主机配置文件时,BizTalk无法启动。 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. 将其更正为以下内容应该可以解决您的BizTalk无法启动的问题。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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