I need to add logging to my F# project. For C# code we used: Log4net or NLog (possible two of the most popular logging frameworks for .Net).
What is the best choice to use in F# code? I mean, is there any specific logging framework written for usage in F# code?
One of the most popular solutions for the Java world is the Apache Log4j 2 framework. Maintained by the Apache Foundation, Log4j 2 is an improvement on the original Log4j, which was the most popular logging framework in Java for many years.
Spring Boot's default logging framework is Logback. Your application code should interface only with the SLF4J facade so that it's easy to switch to an alternative framework if necessary. Log4j2 is newer and claims to improve on the performance of Logback.
NLog. NLog is one of the most popular, and one of the best-performing logging frameworks for . NET. Setting up NLog is fairly simple.
Logging frameworks offer flexibility and prevent you from reinventing the wheel.
https://github.com/logary/logary
I'm the author of Logary, which supports logging, metrics and distributed tracing for .Net Core.
Targets include: TextWriter, Console, LiterateConsole, Debugger, GCP Pub/Sub, GCP BigQuery, GCP Stackdriver, Jaeger, TCP (Shipper), UDP (Shipper), ZeroMQ (Shipper) Elasticsearch, Graphite/statsd, elmah.io, Aliyun, Azure ApplicationInsights, Mixpanel (commercial), OpsGenie (commercial), Server-sent-events (web push).
Further, you can expose a HTTP server for Proemetheus to scrape with Logary.Prometheus.
It also has a Dash service that supports real-time push of logs to your web browser.
Further, Logary Rutta is a sidecar container implementation or stand-alone log router for the cloud-native era.
Logary JS is a logging and metrics library for JavaScript that can ship into Logary Rutta on the server side, from where you can then furthr the logs to any of the available targets.
Logary Facade is an Apache 2-licensed facade you can copy-n-paste into all your C# and F# libraries and get high-quality console logging with.
Logary is written in F# for F# primarily.
Install-Package Logary
docs here
All of the above is free to use for non-commercial purposes. You can see the different licenses here.
As far as I know, they're the same for F#, i.e. there's nothing F# specific about them (whether good or bad). Aside from configuration, usage is pretty much the same for all logging libraries.
What you might want to add is printf-enabled logging, so instead of logger.DebugFormat("Hello {0}", "world")
or logger.Debug(sprintf "Hello %s" "world")
you can just do logger.Debugf "Hello %s" "world"
. Use type extensions and kprintf to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With