none
Trace.Refresh() causing listener filter to be set to null RRS feed

  • Question

  • Hello, 
    I'm seeing an issue where a call to Trace.Refresh() is causing my to lose the TraceFilter from the TraceListener on the TraceSource.

    Basically, as soon as Trace.Refresh() is called, the Filter gets set to null. To simplify things I tried the sequence in a very simple app, and it still happens; The config file and code are shown below.
    Any ideas if this should be supported functionality of the TraceSource?

    Thanks in advance.


    Output from following code:

    MySource Information: 0 : I have a filter
    MySource Information: 0 : I have no filter



    Config file;
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.diagnostics>
    <sources>
    <source name="MySource" switchValue="Verbose">
    <listeners>
    <add type="System.Diagnostics.ConsoleTraceListener" name="consoleListener">
    <filter type="System.Diagnostics.EventTypeFilter"
    initializeData="Information" />
    </add>
    </listeners>
    </source>
    </sources>
    </system.diagnostics>
    </configuration>


    using System;
    using System.Diagnostics;

    namespace TraceRefresh
    {
    class Program
    {
    static void Main(string[] args)
    {
    TraceSource ts = new TraceSource("MySource");

    if (ts.Listeners["consoleListener"].Filter != null)
    ts.TraceData(TraceEventType.Information, 0, "I have a filter");
    Trace.Refresh();

    if (ts.Listeners["consoleListener"].Filter == null)
    ts.TraceData(TraceEventType.Information, 0, "I have no filter");

    while (Console.ReadLine() != "");
    }
    }
    }

    Monday, December 8, 2008 5:33 PM