以编程方式/动态方式添加WCF服务跟踪日志记录 [英] Adding WCF Service Trace Logging programmatically/Dynamically

查看:64
本文介绍了以编程方式/动态方式添加WCF服务跟踪日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的app.config中设置了WCF跟踪,如下所示:

I currently have WCF Tracing set in my app.config like so :

<system.diagnostics>
<trace autoflush="true">
  <listeners>
  </listeners>
</trace>
<sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing">
    <listeners>
      <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="WcfDetailTrace.svclog" />
    </listeners>
  </source>
</sources>

这可以按预期工作,但是,我希望能够以编程方式/动态方式将日志文件的文件位置和文件名设置为除 WcfDetailTrace.svclog

This works as expected, however, I want to be able to programmatically/Dynamically set the file location and filename of my log file to something other than WcfDetailTrace.svclog

目前,我已尝试将其添加到我的服务主机中:

Currently I have tried adding this to my Service Host:

   TraceSource ts = TraceSource ( "System.ServiceModel" );
   var 侦听器 = XmlWriterTraceListener ( SomeCustomFilename + .svclog"" "std2"; );           
   ts
. 侦听器 . ( );

   TraceSource ts = new TraceSource("System.ServiceModel");               
   var listener = new XmlWriterTraceListener(SomeCustomFilename + ".svclog", "std2");          
   ts
.Listeners.Add(listener);

以上内容似乎只是在我将数据记录到我的自定义文件中时使用方法 ts.TraceData()

The above only seems to log data into my custom file when I  use the method ts.TraceData()

是否有办法进行所有WCF日志记录,该日志记录当前已放入文件 WcfDetailTrace.svclog 进入我的自定义文件?

Is there someway to make all the WCF logging, that currently goes into file WcfDetailTrace.svclog to go into my custom file instead?

我将基于从命令行向控制台应用程序发送的参数设置 SomeCustomFilename .

I will set the SomeCustomFilename based on a parameter sent into the Console application from the commandLine.

感谢


推荐答案

您好Candreoutrade,

Hi Candreoutrade,

据这种情况,据我所知,当我们创建一个自定义监听器类时,

According to this case, as far as I know, when we create a  custom listener class which

.如果您想要所有跟踪输出的文本记录,

is mentioned in the config.if you want a text record of all trace output,

创建一个TextWriterTraceListener侦听器,该侦听器将所有输出写入一个新的文本文件

create a TextWriterTraceListener listener, which writes all output to a new text file

启用后.

有关更多信息,请参阅以下文章:

For more information, please refer to the following articles:

1.如何:创建和初始化跟踪侦听器

2.如何启用/通过代码禁用WCF跟踪

最好的问候,

Grady


这篇关于以编程方式/动态方式添加WCF服务跟踪日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆