Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptLog.info and the other helpers work in any environment. They write to the runtime's ILogSink, not a service in
an application record. The default writes Information and above to stderr; it does not write to stdout.
Use LogSink.none to silence a test or Log.memory () to record entries.
Show page setup
open Axial
open Axial
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actuallet recordAttempt name : Flow<'env, Never, unit> = Log.info $"Processing {name}"
let everyLevel (error: exn) : Flow<'env, Never, unit> =
flow {
do! Log.trace "trace"
do! Log.debug "debug"
do! Log.info "info"
do! Log.warning "warning"
do! Log.error "error"
do! Log.critical "critical"
do! Log.errorExn error "error with exception"
do! Log.criticalExn error "critical with exception"
do! Log.log LogLevel.Information "chosen level"
do! Log.logException LogLevel.Warning error "chosen exception level"
}
recordAttempt: 'a -> Flow<'env,Never,unit>name: 'aAxial.Flow`3envAxial.NeverRepresents an error channel that cannot occur.
unitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
Axial.LogHelpers for the logging service.
info: string -> Flow<'env,'error,unit>Writes an informational message to the installed log sink.
everyLevel: exn -> Flow<'env,Never,unit>error: exnexnAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
trace: string -> Flow<'env,'error,unit>Writes a trace message to the installed log sink.
debug: string -> Flow<'env,'error,unit>Writes a debug message to the installed log sink.
warning: string -> Flow<'env,'error,unit>Writes a warning message to the installed log sink.
error: string -> Flow<'env,'error,unit>Writes an error message to the installed log sink.
critical: string -> Flow<'env,'error,unit>Writes a critical message to the installed log sink.
errorExn: exn -> string -> Flow<'env,'error,unit>Writes an error message carrying an exception to the installed log sink.
criticalExn: exn -> string -> Flow<'env,'error,unit>Writes a critical message carrying an exception to the installed log sink.
log: LogLevel -> string -> Flow<'env,'error,unit>Writes only if the current destination enables this level.
Axial.LogLevelInformationlogException: LogLevel -> exn -> string -> Flow<'env,'error,unit>Writes a message carrying an exception to the installed log sink.
WarningRequires & types
Requires: open Axial (packages: Axial)val recordAttempt: 'a -> Flow<'env,Never,unit>val everyLevel: exn -> Flow<'env,Never,unit>Exceptions remain objects in LogEntry.Error, preserving their stack and identity. Each entry also contains
Level, Message, an Annotations map and a snapshot of explicitly set named FiberLocal values in Locals.
ILogSink.IsEnabled is checked before building the entry; a disabled call builds no record or metadata snapshot.
Exceptions thrown by a sink's gate or writer are guarded and cannot change the flow's outcome.
Replace or compose a sink
Flow.withLogSink sink replaces the destination within its subtree. Descendant fibers inherit it, and leaving the
scope restores the outer sink. Flow.mapLogSink decorate instead transforms the destination already in force.
| Combinator | Behavior |
|---|---|
LogSink.none |
Disabled destination |
LogSink.fromFunction write |
Calls a function with each enabled LogEntry |
LogSink.console minimum |
Information-style level prefix on stderr at a chosen minimum |
LogSink.minLevel minimum sink |
Rejects lower levels before entry creation |
LogSink.filter predicate sink |
Filters complete entries, after they are built |
LogSink.map transform sink |
Transforms entries and checks the mapped level against the destination gate |
LogSink.tee first second |
Sends enabled entries to both guarded destinations |
Log.live is the default console sink, not a no-op. LogSink.none is a no-op, and LogSink.fromFunction accepts a
LogEntry -> unit function. These are convenience values; there is no logging layer to put into 'env.
let first = Log.memory ()
let second = Log.memory ()
let combined = LogSink.tee first second |> LogSink.minLevel LogLevel.Information
let workflow: Flow<unit, Never, unit> = flow {
do! Log.debug "disabled"
do! recordAttempt "invoice 7"
let! child = Log.info "child" |> Flow.fork
do! Fiber.join child
}
workflow |> Flow.withLogSink combined |> Flow.annotate "request" "req-7" |> Flow.run () |> shouldEqual (Exit.Success ())
first.Entries |> Seq.map _.Message |> Seq.toList |> shouldEqual ["Processing invoice 7"; "child"]
second.Entries |> Seq.forall (fun entry -> entry.Annotations.["request"] = "req-7") |> shouldEqual true
first.Clear()
everyLevel (InvalidOperationException "boom") |> Flow.withLogSink first |> Flow.run () |> ignore
first.Entries.Count |> shouldEqual 10
first: TestLogAxial.LogHelpers for the logging service.
memory: unit -> TestLogsecond: TestLogcombined: ILogSinkAxial.LogSinkPure decorators for runtime log destinations. Observation failures never escape into the workflow.
tee: ILogSink -> ILogSink -> ILogSink(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
minLevel: LogLevel -> ILogSink -> ILogSinkAxial.LogLevelInformationworkflow: Flow<unit,Never,unit>Axial.Flow`3unitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
Axial.NeverRepresents an error channel that cannot occur.
flow: FlowBuilderThe universal flow { } computation expression.
debug: string -> Flow<'env,'error,unit>Writes a debug message to the installed log sink.
recordAttempt: 'a -> Flow<'env,Never,unit>child: Fiber<Never,unit>info: string -> Flow<'env,'error,unit>Writes an informational message to the installed log sink.
Axial.Flowfork: Flow<'env,'error,'value> -> Flow<'env,'none,Fiber<'error,'value>>Starts a flow in a new fiber without waiting for it to complete. Forking turns a cold flow description into hot child work and returns a handle that can later be joined or interrupted. Prefer zipPar or race when the caller only needs a simple parallel composition. Wait for the handle with Fiber.join or Fiber.awaitExit, and stop it with Fiber.interrupt. The fiber runs in its own scope and releases its scoped resources (anything registered with a scope, such as scopeResource, scopeFinalizer, or a hub subscription) when it settles, whether or not anyone joins it. A value the fiber returns therefore outlives the scoped resources the fiber acquired: a resource returned through Fiber.join has already been released. Use forkResource to acquire a resource in the background and keep it, or zipPar and sequencePar to acquire several in parallel. The flow to fork. A flow that produces a handle.
Axial.FiberModuleOperations on a running , the handle returned by Flow.fork. Every operation returns a flow; nothing waits or interrupts until that flow runs. Reading a fiber's outcome through join, await, or interrupt marks it observed, so a defect it died with is not also reported as unobserved.
join: Fiber<'error,'value> -> Flow<'env,'error,'value>Waits for a fiber and returns its value, failing the same way the fiber failed. Joining preserves the child's error channel: a Cause.Fail becomes the same typed error, and interruption and defects remain interruption and defects. Use awaitExit to inspect the outcome instead. The fiber to join. A flow that completes with the fiber's value. let loadProfile : Flow<unit, string, string> = Flow.ok "profile" let loadOrders : Flow<unit, string, int list> = Flow.ok [ 1; 2 ] let page = flow { let! fiber = Flow.fork loadProfile let! orders = loadOrders let! profile = Fiber.join fiber return profile, orders }
withLogSink: ILogSink -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Replaces the log destination within this flow and its descendants.
annotate: string -> string -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Adds a runtime annotation for the duration of the supplied flow. Annotations are runtime metadata for diagnostics, logging, metrics, and tracing. Nested annotations with the same key override the outer value for the nested flow only. The annotation key. The annotation value. The source flow. A flow that runs with the supplied annotation in the ambient runtime context.
run: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
shouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Entries: Collections.Generic.IReadOnlyList<LogEntry>The recorded entries, in the order they were written.
Microsoft.FSharp.Collections.SeqModuleContains operations for working with values of type .
map: ('T -> 'U) -> 'T seq -> 'U seqBuilds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The given function will be applied as elements are demanded using the MoveNext method on enumerators retrieved from the object. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently. Sequence construction is O(1). Enumeration is O(n), where n is the length of the sequence. A function to transform items from the input sequence. The input sequence. The result sequence. Thrown when the input sequence is null. let inputs = ["a"; "bbb"; "cc"] inputs |> Seq.map (fun x -> x.Length) Evaluates to a sequence yielding the same results as seq { 1; 3; 2 }
_arg1: LogEntryMessage: stringtoList: 'T seq -> 'T listBuilds a list from the given collection. The input sequence. The result list. Thrown when the input sequence is null. let inputs = seq { 1; 2; 5 } inputs |> Seq.toList Evaluates to [ 1; 2; 5 ]. This is an O(n) operation, where n is the length of the sequence.
forall: ('T -> bool) -> 'T seq -> boolTests if all elements of the sequence satisfy the given predicate. The predicate is applied to the elements of the input sequence. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned. This is an O(n) operation in the worst case, where n is the length of the sequence. A function to test an element of the input sequence. The input sequence. True if every element of the sequence satisfies the predicate; false otherwise. Thrown when the input sequence is null. let isEven a = a % 2 = 0 [2; 42] |> Seq.forall isEven // evaluates to true [1; 2] |> Seq.forall isEven // evaluates to false
entry: LogEntryAnnotations: Map<string,string>Item: stringLookup an element in the map. Raise KeyNotFoundException if no binding exists in the map. The input key. Thrown when the key is not found. The value mapped to the key. Maps are represented as binary trees so this is an O(log n) operation, where n is the number of bindings in the map. let sample = Map [ (1, "a"); (2, "b") ] sample.[1] // evaluates to "a" sample.[3] // throws KeyNotFoundException
(=): 'T -> 'T -> boolStructural equality The first parameter. The second parameter. The result of the comparison. 5 = 5 // Evaluates to true 5 = 6 // Evaluates to false [1; 2] = [1; 2] // Evaluates to true (1, 5) = (1, 6) // Evaluates to false
Clear: unit -> unitRemoves all recorded entries.
everyLevel: exn -> Flow<'env,Never,unit>``.ctor``: string -> unitInitializes a new instance of the class with a specified error message. The message that describes the error.
ignore: 'T -> unitIgnore the passed value. This is often used to throw away results of a computation. The value to ignore. ignore 55555 // Evaluates to ()
Count: intGets the number of elements in the collection. The number of elements in the collection.
Requires & types
Requires: open Axial (packages: Axial)val first: TestLogval second: TestLogval combined: ILogSinkval workflow: Flow<unit,Never,unit>TestLog.Entries returns a thread-safe snapshot; Clear() removes subsequent recorded state, not earlier snapshots.
Flow.runTest installs a fresh recording log automatically; TestPlatform.create () and Flow.runTestWith expose
that instance for assertions. Flow.mapLogSink (LogSink.tee auditSink) adds a second destination to just one subtree.
Host adapters
- Generic Host installs a Microsoft logging sink at the root, category
Axial. - ASP.NET Core installs one per
flowEndpointrequest (cached perILoggerFactory), categoryAxial.Endpoint. - GenHTTP has no logging abstraction;
EndpointOptions.LogSinkis optional and otherwise leaves the runtime default. - Node installs
NodeLogging.sinkLogLevel.Informationthroughconsole.erroron stderr. Browser entry points useBrowserLogging.sink, mapping levels toconsole.debug/info/warn/error. Both preserve exception and metadata arguments, and treat percent directives in message text literally.
Host options replace or omit installation; an inner Flow.withLogSink always wins. None leaves the runtime
default, while a supplied LogSink.none silences logging.
MicrosoftLogging.sink logger and MicrosoftLogging.fromFactory category factory live in Axial.Hosting.
They use the host's level gate and map annotations plus named locals to a BeginScope dictionary. No empty scope
is opened when both are empty. Providers must enable scope capture to display those fields.
open Axial
open Axial.Hosting
let hosted factory application =
application |> Flow.withLogSink (MicrosoftLogging.fromFactory "App" factory)FiberLogging.observe logger remains a separate, opt-in observer for defects. Installing a host log sink does not
silently enable it. See the .NET hosting guide.
Logging and telemetry
Logging emits application messages. Spans, metrics and typed attributes describe execution structure; see
observability. Flow.withTelemetry replaces both ITelemetry observation callbacks
for a subtree. The Activity and JavaScript OpenTelemetry adapters tee through the existing callbacks; neither
installs a log sink. Compose destinations explicitly when they should share a backend.

