开发者

How to configure message filtering through switches

开发者 https://www.devze.com 2023-02-08 17:08 出处:网络
Here is my code public static TraceSource TS = new TraceSource(\"myTraceSrc\", SourceLevels.All); static void Main(string[] args)

Here is my code

 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");

}

here is config file

<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>

I want all my messages to go to console and text file but only error should go to events log. How can I set it up using configuration settings?


Try to use logging libraries (Nlog, log4net) for your tasks. They have message filtering and routing.

0

精彩评论

暂无评论...
验证码 换一张
取 消