Skip to content

Latest commit

History

144 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Destructurama.FSharp

ATTENTION! Looking for maintainers

See #34

License

codecovNugetNuget

GitHub Release DateGitHub commits since latest release (by date)Size

GitHub contributorsActivityActivityActivity

Run unit testsPublish preview to GitHub registryPublish release to Nuget registry

Native support for destructuring F# types when logging to Serilog.

Installation

Install from NuGet:

dotnet add package Destructurama.FSharp

Usage

Add Destructure.FSharpTypes() to your logger configuration:

openSerilog[<EntryPoint>]letmain argv = Log.Logger <- LoggerConfiguration()
.Destructure.FSharpTypes()
.WriteTo.Console()
.CreateLogger()
Log.Information("Drawing a {@Shape}", Circle 5.)0

Discriminated unions like:

typeShape=| Circle ofRadius:double| Rectangle ofWidth:double*Height:double| Arc // ...letshape= Circle 5.

When logged with Serilog:

Log.Information("Drawing a {@Shape}", shape)

Are printed nicely like:

2015-01-14 16:58:31 [Information] Drawing a Circle { Radius: 5 }

Depending on the log storage you use you will be able to query on the tag as well as the fields (like Radius) from the union.

More samples can be seen by running the project in the Samples folder using dotnet run. Doing so will destructure a union, record, and a tuple with and without this package to highlight the difference:

➜ samples git:(records) ✗ dotnet run
[13:35:19 INF] Printing a {"quantity": 10, "label": "hi", "Tag": 2, "IsA": false, "IsB": false, "IsC": true, "$type": "C"} with poor destructuring
[13:35:19 INF] Printing a {"quantity": 10, "label": "hi", "$type": "C"} with better destructuring
[13:35:19 INF] Printing a {"FieldA": 10, "OtherField": true, "AnotherOne": {"quantity": 10, "label": "hi", "Tag": 2, "IsA": false, "IsB": false, "IsC": true, "$type": "C"}, "$type": "MyRecord"} with poor destructuring
[13:35:19 INF] Printing a {"FieldA": 10, "OtherField": true, "AnotherOne": {"quantity": 10, "label": "hi", "$type": "C"}, "$type": "MyRecord"} with better destructuring
[13:35:19 INF] Printing a {"Item1": 1, "Item2": "hi", "$type": "Tuple`2"} with poor destructuring
[13:35:19 INF] Printing a [1, "hi"] with better destructuring

About

Native support for destructuring F# types when logging to Serilog.

Resources

Stars

44 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages