以下是我的代码
public static TraceSource TS = new TraceSource("myTraceSrc", SourceLevels.All);
static void Main(string[] args)
{
TS.TraceInformation("Hello Information Trace from Main");
TS.TraceEvent(System.Diagnostics.TraceEventType.Error, 1, "Hello Error Trace from Main");}
这是配置文件
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="myTraceSrc" switchName="switch1" >
<listeners>
<add type="System.Diagnostics.TextWriterTraceListener" name="myLocalListener" initializeData="c:\WasteBin\Test.Log" />
<add name="consoleListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add type="System.Diagnostics.ConsoleTraceListener" name="consoleListener" traceOutputOptions="None" />
<add type="System.Diagnostics.EventTypeFilter" name="EventListener" traceOutputOptions="None" />
</sharedListeners>
<switches>
<add name="switch1" value="all" />
</switches>
</system.diagnostics>我希望我的所有消息到控制台和文本文件,但只有错误应该到事件日志。如何使用配置设置进行设置?
发布于 2011-02-03 00:26:11
尝试使用日志库(Nlog、log4net)来执行任务。它们具有消息过滤和路由功能。
https://stackoverflow.com/questions/4876201
复制相似问题