Use JsonlRecordSink to save a local run as JSON Lines: one event per line.
dotnet add package RecursiveAI.OneLlmRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneLlm; using OneLlm.Records; using OneLlm.Testing; var runtime = new Runtime(); var sink = new JsonlRecordSink("records"); runtime.Sinks.Add(sink); var model = new ScriptedProvider("openai"); model.EnqueueText("Four."); runtime.Providers.Set("openai", model); var run = await runtime.AskAsync(new AskRequest { Model = "gpt-6-luna", Prompt = "What is 2 + 2?" }); Console.WriteLine(run.Text);
Unzip the example, then dotnet run.
Writes records/<instanceId>.jsonl. The prompt and reply are in the code; OneLLM’s scripted provider returns the reply offline, with no key or local model server. The gpt-6-luna name selects the scripted route here; the sink doesn’t use it. Prints:
Four.The full program
The download gets the exact file path from PathOf, reads the records back, and prints their kinds in order.
using OneLlm; using OneLlm.Records; using OneLlm.Testing; var runtime = new Runtime(); var sink = new JsonlRecordSink("records"); runtime.Sinks.Add(sink); runtime.Sinks.OnError = (_, error) => Console.Error.WriteLine(error.Message); var model = new ScriptedProvider("openai"); model.EnqueueText("Four."); runtime.Providers.Set("openai", model); var run = await runtime.AskAsync(new AskRequest { Model = "gpt-6-luna", Prompt = "What is 2 + 2?" }); string path = sink.PathOf(run.Instance.InstanceId); Console.WriteLine(string.Join(", ", RecordReader.ReadFile(path).Select(record => record.Kind)));
dotnet run prints:
run, message, inference, message, runThat’s the start of the run, the prompt, the model call, the reply, and the end of the run. If writing fails (for example, the directory isn’t writable), OneLLM calls Sinks.OnError and continues the run; the download sends that error to standard error.
Variations
Read the provider and operation from inference records. Add this after path is set in the full program. It reads the existing file; it doesn’t call the model.
foreach (var record in RecordReader.ReadFile(path)) if (record.Kind == "inference") { Console.WriteLine( record.Json.GetProperty("provider").GetString()); Console.WriteLine( record.Json.GetProperty("operation").GetString()); }
openai chat
Use a local model server instead. Keep the sink, but replace the scripted provider setup with the Ollama preset registration in Call Ollama from C# and set Model to ollama:llama3.2 if that model is installed.
Related recipes
The short answer
Add a JsonlRecordSink to the OneLLM runtime before you start the run, then use the result’s instance ID to find the file. The sink appends records to that instance’s .jsonl file as the run produces them. Changing the model provider doesn’t change where the records go; the sink belongs to the runtime, not to the model server.
What is the difference between JSON and JSONL format?
A plain JSON file usually represents a single value, such as an array of records. In JSON Lines, each line is a JSON value of its own. OneLLM appends one object at a time without reopening an array or adding commas between objects. That makes a file convenient to inspect even if a run is still producing events. Whitespace inside a value is escaped where needed; don’t pretty-print the objects across several lines if you want to keep the file in JSONL format.
OneLLM uses kind to tell you how to interpret a record. A run record may mark a start or an end, so kind alone doesn’t tell you which one it is. The first line of one example run was:
{"kind":"run","time":"2026-11-20T12:12:12.3865369Z","instanceId":"i-43650ddd87434e41a550debb085560c4","event":"started","state":"running","model":"gpt-6-luna"}Each run generates its own instance ID and timestamps. Records without an instance ID go to _runtime.jsonl rather than to a run file.
How do you read a JSONL file in C#?
RecordReader.ReadFile returns the file’s records in order and gives you the parsed JSON payload on each record’s Json property. It returns an empty list for a missing file, so if a run completed but you get no records, check the directory and the sink’s error callback. For long files you can read one line at a time with File.ReadLines and parse each nonempty line with RecordReader.ParseLine:
foreach (var line in File.ReadLines(path)) if (line.Length != 0) Console.WriteLine(RecordReader.ParseLine(line).Kind);
This prints the same five kinds as the full program, one per line, without first loading all the records into a list.
What is the difference between tracing and logging?
Use the JSONL file to inspect what happened inside one OneLLM instance in order. It includes message records, so it can hold application input and model replies. It’s not the saved state you’d use to resume a run, and it doesn’t export a distributed trace. Use OneLLM’s OpenTelemetry spans when you want to see where model calls fit into a trace of a larger operation. Those spans don’t contain prompts, completions, or tool arguments. You can use both: traces to follow a request across services, and local records to inspect a specific instance.