Trace.WriteLine doesn't work

Options
Is it normal that Trace.WriteLine doesn't work in anyway, when I run the code with just a few line of Trace.WriteLine, nothing happen even if I add any kind of TraceListener, and what is weird is that the IL is completly empty.

void Main()
{
Trace.Listeners.Clear();
Trace.Listeners.Add(new ConsoleTraceListener());

Trace.WriteLine("adads");
Trace.WriteLine("adads");
Trace.WriteLine("adads");
}

IL

IL_0001: call System.Diagnostics.Trace.get_Listeners
IL_0006: callvirt System.Diagnostics.TraceListenerCollection.Clear
IL_000B: nop
IL_000C: call System.Diagnostics.Trace.get_Listeners
IL_0011: newobj System.Diagnostics.ConsoleTraceListener..ctor
IL_0016: callvirt System.Diagnostics.TraceListenerCollection.Add

As you can see the IL stops just after the adding of the listener.

If I run only some Trace

void Main()
{
Trace.WriteLine("adads");
Trace.WriteLine("adads");
Trace.WriteLine("adads");
}

No IL at all!

It seems like linqpad doesn't like Trace stuff, and removes them all before running the code.

I'm running the version v4.51.03

Thanks for any suggestions.

Comments