我有一个应用程序,它将其跟踪源配置如下:
var traceSource = new TraceSource("MyTraceSource");
traceSource.Switch = new SourceSwitch("MyTraceSwitch") { **Level = SourceLevels.Information** };
var traceListener = new TextWriterTraceListener(logFilePath);
traceListener.TraceOutputOptions = TraceOptions.DateTime;
traceSource.Listeners.Clear();
traceSource.Listeners.Add(traceListener);
Trace.AutoFlush = true;应用程序始终使用此跟踪源来跟踪事件。请注意,SourceLevels.Information是在跟踪开关中硬编码的。现在,我需要将跟踪开关级别更改为Verbose。可以通过app.config文件来完成吗?我尝试了许多xml-configs,但都失败了。注意:我不能只更改app.config的源代码。
发布于 2013-02-18 16:13:28
我不确定您是否在搜索类似的内容,但我曾经使用过以下xml配置:change the trace switch level to Verbose.(App-Config)
<configuration>
<system.diagnostics>
<switches>
<add name="AppTraceLevel" value="4" /> //4 = Verbose
</switches>
// Here would be the Trace Tag with the Listeners (not important for your question)
</system.diagnostics>
</configuration>也许这会有帮助
发布于 2013-02-18 16:14:10
Well - Configuring Tracing明确规定:
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
</source>
</sources>“跟踪级别”部分介绍了一些详细信息。
发布于 2013-02-23 12:34:56
上面的两个答案都有价值。以下是完整的响应。将此部分添加到您的配置中:
<system.diagnostics>
<sources>
<source name="MyTraceSource" switchValue="Information">
<listeners>
<add name="file" initializeData="c:\temp\logpath.txt" traceOutputOptions="DateTime" type="System.Diagnostics.TextWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</listeners>
</source>
</sources>
</system.diagnostics>https://stackoverflow.com/questions/14891089
复制相似问题