bohdan_trotsenko
bohdan_trotsenko

Reputation: 5357

How to enable Tracing in F# interactive

I'd like to view the output of a library that I use.

It prints intermediate info with a simple Trace, and for my experiments I use F# Interactive.

What I've tried:

Console.Out.WriteLine("Hello")                                      // prints "Hello" :)
type MyListener() =
    inherit TraceListener()
    override u.Write (msg : string) = printf "Trace: %s" msg
    override u.WriteLine (msg : string) = printfn "Trace: %s" msg
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out))       // prints "val it : int = 1"
Trace.Listeners.Add(new MyListener())                               // prints "val it : int = 2"
Trace.AutoFlush <- true                                             // prints "val it : unit = ()"
Trace.TraceInformation("test")                                      // prints "val it : unit = ()".

Nothing 'test'-related is produced with the last line. Apparently, I need to enable a debugging flag or set a property.

How do I Trace?

Upvotes: 2

Views: 880

Answers (1)

Martin
Martin

Reputation: 930

I found out about this when trying to debug a library I was planning to use in Azure, where tracing is among the more useful logging options. In VS2013 you can set the flags that get passed to the FSI in Tools -> Options -> F# Tools -> F# interactive. This allows me to read the trace output in the fsi window.

I have set mine to read: --optimize- --readline+ --debug+ -d:TRACE

screenshot of fsi settings

Upvotes: 2

Related Questions