FAKE - F# Make - A DSL for build tasks and more FAKE
6.1.3
Edit this page

Lookig for older versions of the documentation, pre FAKE v6? See 

v5.fake.build

Fake.Core.Trace module

To see the available Trace APIs in FAKE, please see the API-Reference for the Trace module.

Logging and Tracing

The Trace module allows to trace and output stuff into the console or to your custom environment.

#r "paket:
nuget Fake.Core.Trace //"
open Fake.Core

Trace.log "Some Information message"
Trace.logfn "Some formatted message: %s" "parameter"

Trace.trace "Some trace message"

Trace.traceImportant "Some important message"
Trace.traceFAKE "Some important message %s" "with formatting"

Trace.traceError "Trace some error"

try doSomething()
with e -> Trace.traceException e

Trace.traceLine()

Target.create "mytarget" (fun _ ->
    use __ = Trace.traceTask "MyOperation" "Description"
    // do my operation
    __.MarkSuccess()
)

Custom Listeners

You can implement and set custom listeners in your fake script in order to generate custom output suitable for your environment.

#r "paket:
nuget Fake.Core.Trace //"
open Fake.Core

let mylistener =
    { new ITraceListener with
        member x.Write msg =
            match msg with
            | StartMessage -> ()
            | OpenTag _ -> ()
            | CloseTag _ -> ()
            | ImportantMessage text | ErrorMessage text ->
                printfn "IMPORTANT: %s" text
            | LogMessage(text, newLine) | TraceMessage(text, newLine) ->
                printfn "LOG: %s" text
            | FinishedMessage -> ()
    }

CoreTracing.setTraceListener [mylistener]

Protect secrets

The Trace-Api will filter out any registered secrets before printing them into the output.

#r "paket:
nuget Fake.Core.Trace //"
open Fake.Core

// Register your secrets at the start
let secret = Environment.environVarOrDefault "nugetkey" ""
TraceSecrets.register "<REPLACEMENT>" secret

// Later FAKE will replace them and not output them (when using the FAKE-Tracing capabilites)
let cmdLine = sprintf "nuget.exe push -ApiKey %s" secret
Trace.log "NuGet failed while executing: %s" cmdLine