2012-04-11 51 views
8

即时通讯使用Microsoft服务配置编辑器来设置诊断(WCF日志),我找不到任何方式来设置最大文件大小?WCF日志记录,设置最大文件大小?

我发现了MaxSizeOfMessageToLog,但是对文件大小没有任何作用?

编辑1:根据这个:http://msdn.microsoft.com/en-us/library/aa395205.aspx 应该有在sharedListeners水平maxFileSizeKB但在加载标签打空间时,我不明白键入maxFileSizeKB的可能性?

编辑2:当添加maxFileSizeKB中的service将不再启动,而不是我将得到以下EXCETION:

“maxFileSizeKB”不是类型的有效配置属性“System.Diagnostics.XmlWriterTraceListener ”。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。 异常详细信息:System.Configuration.ConfigurationErrorsException:'maxFileSizeKB'不是类型为'System.Diagnostics.XmlWriterTraceListener'的有效配置属性。 源错误: 执行当前Web请求期间生成未处理的异常。关于异常的来源和位置的信息可以使用下面的异常堆栈跟踪来标识。

编辑3:

我必须下载该通函的TraceListener样品,并将其包含在我的项目,没有内置的档案大小限制。

我的配置现在看起来是这样的:

<system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
     <listeners> 
      <add name="ServiceModelMessageLoggingListener"/> 
     </listeners> 
     </source> 
     <source name="System.ServiceModel" switchValue="Warning,ActivityTracing" 
     propagateActivity="false"> 
     <listeners> 
      <add name="ServiceModelTraceListener"/> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="C:\My\MyRelease 0.31\Host\My.Host.Dev\web_messages.svclog" 
     type="Microsoft.Samples.ServiceModel.CircularTraceListener,CircularTraceListener" 
     name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp" maxFileSizeKB="1024"> 
     <filter type="" /> 
     </add> 
     <add initializeData="C:\My\MyRelease 0.31\Host\My.Host.Dev\web_tracelog.svclog" 
     type="Microsoft.Samples.ServiceModel.CircularTraceListener,CircularTraceListener" 
     name="ServiceModelTraceListener" traceOutputOptions="Timestamp" maxFileSizeKB="1024"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 

这限制了消息日志文件,但没有跟踪日志文件?

+0

请问您可否包括您的配置部分? – 2012-04-11 07:26:50

+0

btw - 这里是'CircularTraceListener'的代码:https://cbasetest.svn.codeplex.com/svn/SoftLibrary_Dev/SDFL/Reputation/RepuService/FrontEndCommon/CircularTraceListener.cs – 2012-04-11 07:28:19

+0

btw,你有没有试过利用“微软服务配置编辑器“(”C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Bin \ NETFX 4.0 Tools \ SvcConfigEditor.exe“) – 2012-04-11 07:32:58

回答

11

这是因为您提供的链接使用了自定义的跟踪侦听器(“Microsoft.ServiceModel.Samples.CircularTraceListener”),它具有“maxFileSizeKB”属性。

没有内置函数来限制/滚动svclog文件,因此您确实需要使用自定义跟踪侦听器。 您可以使用链接中使用的示例(阅读文章末尾的如何下载代码)。或者这里是another one可以是有用的。

+0

哎呀,你在我打字的时候更新了你的问题:) – Fabske 2012-04-11 08:27:39

7

只是要添加到@Fabske回答序这个工作

1)下载WCF样本: http://go.microsoft.com/fwlink/?LinkId=150780

2)打开 :\ WF_WCF_Samples \ WCF \基本\管理\ CircularTracing

3)构建的解决方案,抓住CircularTraceListener.dll

4)该DLL添加到您的项目引用

5)更新您的配置,如图所示http://msdn.microsoft.com/en-us/library/aa395205(v=vs.100).aspx

+2

还要注意MSDN文章中的命名空间错字(正如评论员指出的),免得你浪费了一堆时间,就像我试图弄清楚为什么你的项目赢了' t运行... – 2013-10-31 16:38:58

+0

我做到了。下载的样本,构建.dll,将其放入我的项目的引用,做了配置的事情,并关心错字(这是不存在的)。但''mxFileSizeKB''仍然被标记为未知,我没有得到一个文件。 – ecth 2015-04-15 07:45:25

+1

好的。管理它。我的代码:http://pastebin.com/JeYE3rEt。 ''maxFilesizeKB''仍然被标记为未知,但它工作并且文件保持正确的大小。另外我的switchValue是''All'',你可能想把它设置为''Information'',''Warning''或类似的东西) – ecth 2015-04-15 08:32:23