loggingasp.net-coref#saturn-framework

How to change log level in F# Saturn Framework?


When I run my Saturn app, I see some logs being written to the console.

Looks like they start with the LogLevel.Info. How do I engage more detailed logging, i.e. how to properly set e.g. LogLevel.Trace?


Solution

  • A way to go is setting logging in the Saturn app builder:

    let app = application {
        pipe_through endpointPipe
    
        router topRouter
        url "http://0.0.0.0:8085/"
        memory_cache
        use_static "static"
        use_gzip
        logging configureLogging
    }
    

    And you can do configuration like this:

    let configureLogging (logging: ILoggingBuilder) =
        logging.SetMinimumLevel(LogLevel.Trace) |> ignore
    

    The only Saturn example I found is here, in the Saturn samples. There are more for ASP.NET Core, on top of which Saturn is built.

    The default log level is indeed LogLevel.Info:

    If you don't explicitly set the minimum level, the default value is Information, which means that Trace and Debug logs are ignored.

    Remember not to set LogLevel.Trace for production:

    These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.