Comments (11)
FYI, Suave.SerilogExtensions implements a proper destructuring mechanism for F# types (using Json -> LogEvent
) see Destructure.fs
from fsharp.
Thanks, @cmeeren π
If anyone has any ideas why this would be the case, a PR would be welcome.
from fsharp.
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.
Happy to be of help, hope it's a quick fix. ^_^
from fsharp.
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.
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.
This same structure of struct-handling will hit struct options (valuesome/valuenone) as well.
from fsharp.
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.
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.
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.
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)
- Can a stable package version be published? HOT 2
- Consider using System.Reflection.Emit to generate per-type record and union cons/unconsers HOT 2
- Add the difference example of look with and without destructurama HOT 6
- Add project URL HOT 1
- Depreciate Destructurama.FSharp.NetCore? HOT 4
- Release version without upper bound on FSharp.Core HOT 5
- How to declare from app.config? HOT 2
- Add support for FSharp 5.0 HOT 2
- Weird results for Option, Result, anonymous types HOT 5
- list of lists throws InvalidCastException HOT 2
- Add CodeQL workflow back when supported HOT 1
- Add API approval tests HOT 1
- Increase code coverage to 100% HOT 1
- Looking for maintainers! HOT 6
- Untracked sources issue in nupkg HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharp.