简体   繁体   English

WCF日志记录生成多个svc文件

[英]WCF logging producing multiple svc file

I have a simple WCF service library called HelloService which is hosted in WCF Service application. 我有一个名为HelloService的简单WCF服务库,该库托管在WCF Service应用程序中。

My service is hosted in remote IIS server. 我的服务托管在远程IIS服务器中。 Below is my service configuration for logging. 以下是我的日志记录服务配置。

<system.diagnostics>
<sources>
  <source propagateActivity="true" name="System.ServiceModel" switchValue="Error,ActivityTracing">
    <listeners>
      <add name="xml">
        <filter type="" />
      </add>
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging" switchValue="Error">
    <listeners>
      <add name="xml">
        <filter type="" />
      </add>
    </listeners>
  </source>
  <source name="myUserTraceSource" switchValue="Error,ActivityTracing">
    <listeners>
      <add name="xml">
        <filter type="" />
      </add>
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add initializeData="D:\HelloService\HelloServiceLogs.svclog"
    type="System.Diagnostics.XmlWriterTraceListener" name="xml"
    traceOutputOptions="Timestamp">
    <filter type="" />
  </add>
</sharedListeners></system.diagnostics>

When I call this service, sometimes it logs in existing file and sometimes it creates new file. 当我调用此服务时,有时会登录现有文件,有时会创建新文件。 logFileCreated

My questions are. 我的问题是。

1) Why does it produces so many log files? 1)为什么会产生这么多的日志文件? How to write all logs in one file called. 如何将所有日志写到一个文件中。

2) How can I only log all unhandled exception? 2)如何只记录所有未处理的异常?

1) You can configure the size of messages using a configuration like this: 1)您可以使用以下配置来配置消息的大小:

<system.serviceModel>
  <diagnostics>
    <messageLogging 
         logEntireMessage="true" 
         logMalformedMessages="false"
         logMessagesAtServiceLevel="true" 
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
</system.serviceModel>

Read more here: https://msdn.microsoft.com/en-us/library/ms730064%28v=vs.110%29.aspx 在此处阅读更多信息: https : //msdn.microsoft.com/zh-cn/library/ms730064%28v=vs.110%29.aspx

2) You can setup the level of logging, like this (error only in the example below): 2)您可以像这样设置日志记录级别(仅在以下示例中为错误):

<source propagateActivity="false" name="System.ServiceModel" switchValue="Error">

Hope it helps. 希望能帮助到你。

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

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