Skip to content

destructurama/fsharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Destructurama.FSharp

ATTENTION! Looking for maintainers

See #34

License

codecov Nuget Nuget

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

GitHub contributors Activity Activity Activity

Run unit tests Publish preview to GitHub registry Publish 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:

open Serilog

[<EntryPoint>]
let main argv = 

    Log.Logger <- LoggerConfiguration()
        .Destructure.FSharpTypes()
        .WriteTo.Console()
        .CreateLogger()

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

    0

Discriminated unions like:

type Shape =
    | Circle of Radius : double
    | Rectangle of Width : double *  Height : double
    | Arc // ...
let shape = 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

License

Stars

Watchers

Forks

Packages

No packages published

Languages