Git Product home page Git Product logo

Comments (11)

Zaid-Ajaj avatar Zaid-Ajaj commented on July 25, 2024 3

FYI, Suave.SerilogExtensions implements a proper destructuring mechanism for F# types (using Json -> LogEvent) see Destructure.fs

from fsharp.

nblumhardt avatar nblumhardt commented on July 25, 2024

Thanks, @cmeeren πŸ‘

If anyone has any ideas why this would be the case, a PR would be welcome.

from fsharp.

adamchester avatar adamchester commented on July 25, 2024

Thanks @cmeeren, it seems to be due to this union being a β€˜Structβ€˜ and we did not add support for that kind of union yet. I agree we should add support for this in the same way as other unions.

Thanks again πŸ‘

from fsharp.

cmeeren avatar cmeeren commented on July 25, 2024

Happy to be of help, hope it's a quick fix. ^_^

from fsharp.

adamchester avatar adamchester commented on July 25, 2024

It should be a quick fix, we just need to find the APIs that we can use instead of this

            | t when FSharpType.IsUnion t ->
                let case, fields = FSharpValue.GetUnionFields(value, t)
                let properties = (case.GetFields(), fields) ||> Seq.map2 lep
                result <- StructureValue(properties, case.Name)
                true

from fsharp.

adam-c-anderson avatar adam-c-anderson commented on July 25, 2024

Is this still really open? Just ran this in a test project:

Log.Logger <-
    LoggerConfiguration()
        .Destructure.FSharpTypes()
        .WriteTo.Console(Serilog.Formatting.Json.JsonFormatter())
        .CreateLogger()

type UnionData =
| Label of labelField:string
| Number of int

Log.Information("UnionData Label case {@label}", Label "Foo")
Log.Information("UnionData Number case {@number}", Number 42)
Log.Information("Result Ok case {@ok}", Ok "Bueno")
Log.Information("Result Error case {@error}", Error "Mal")

...and got this output

{"Timestamp":"2019-05-31T11:50:01.4639470-04:00","Level":"Information","MessageTemplate":"UnionData Label case {@label}","Properties":{"label":{"_typeTag":"Label","labelField":"Foo"}}}
{"Timestamp":"2019-05-31T11:50:01.4767652-04:00","Level":"Information","MessageTemplate":"UnionData Number case {@number}","Properties":{"number":{"_typeTag":"Number","Item":42}}}
{"Timestamp":"2019-05-31T11:50:01.4799127-04:00","Level":"Information","MessageTemplate":"Result Ok case {@ok}","Properties":{"ok":{"_typeTag":"Ok","ResultValue":"Bien"}}}
{"Timestamp":"2019-05-31T11:50:01.4807271-04:00","Level":"Information","MessageTemplate":"Result Error case {@error}","Properties":{"error":{"_typeTag":"Error","ErrorValue":"Mal"}}}

from fsharp.

baronfel avatar baronfel commented on July 25, 2024

This same structure of struct-handling will hit struct options (valuesome/valuenone) as well.

from fsharp.

baronfel avatar baronfel commented on July 25, 2024

I believe that all that needs to happen here is for #9 to be updated/finished and to upgrade to a more recent version of FSharp.Core (probably at least 4.6.2). Doing this will update the implementations of the FSharpType.Isxxxxx functions to return appropriate results for struct tuples, records, and unions. here's an example from the .net core FSI for 3.0 preview 7:

> let thing = ValueSome "ok";;
[<Struct>]
val thing : string voption = ValueSome "ok"

> let thingty = thing.GetType();;
val thingty : System.Type =
  Microsoft.FSharp.Core.FSharpValueOption`1[System.String]

> FSharp.Reflection.FSharpType.IsUnion thingty;;
val it : bool = true

from fsharp.

nblumhardt avatar nblumhardt commented on July 25, 2024

Thanks for the notes, @baronfel . This library's in need of some maintenance, if you or anyone following along are keen to jump in and modernize things the help would be appreciated. Cheers!

from fsharp.

baronfel avatar baronfel commented on July 25, 2024

I was planning on doing just that in a couple days/over the weekend. Are you a maintainer here (I'm not sure if the destructurama org is part of serilog proper)?

from fsharp.

nblumhardt avatar nblumhardt commented on July 25, 2024

I'm a maintainer though I'm not actively maintaining :-) ... I haven't touched F# in nearly 10 years, unfortunately

from fsharp.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.