问题
I am editing the Noop.fs file from logary/Noop.fs.
I am currently trying to add two functions. That is the one to create the Event Sourcing connection (I understand I should ideally move it somewhere else, so that it is not created every time I want to log something, but it should rather exist on a global level, where should I add it then?).
The second function is to send the log as an event to the EventStore stream. I have created the function, but I need to call it. Where do I call it? I have tried placing it below the function, but it does not work.
Another error is on this line
ack *<= () (* LHS: the ACK is a unit sent to `ack` *) >>= fun () ->
Error: FS0010 Unexpected identifier in expression. Expected incomplete structured construct at or before this point or other token.
This is my code:
| Log (message, ack) ->
let CreateEventSourcingConnection() =
task {
let connection =
let ipEndPoint = IPEndPoint(IPAddress.Loopback, 1113)
EventStoreConnection.Create(ipEndlPoint)
do! connection.ConnectAsync()
return connection
}
let AddEventToStreamAsync (connection: IEventStoreConnection) streamName eventName message =
task {
let serializedEventData =
message
|> JsonConvert.SerializeObject
|> Encoding.UTF8.GetBytes
let event = EventData(Guid.NewGuid(), eventName, true, serializedEventData, null)
let! _ = connection.AppendToStreamAsync(streamName, int64 ExpectedVersion.Any, event)
()
}
()
//Do something with the `message` value specific to the target
//you are creating.
//Don't put `use` statements in here; you need to dispose them before
//recursing below.
//This is a simple acknowledgement using unit as the signal
ack *<= () (* LHS: the ACK is a unit sent to `ack` *) >>= fun () ->
(* RHS (above): the callback after the ACK is done *)
loop { state = not state.state } // recurse
来源:https://stackoverflow.com/questions/59135700/creating-a-logging-function-from-logary-noop-fs-in-f