Skip to content

DotNET client usage

Chronicle uses connection strings to configure the .NET client. You can pass a connection string to ChronicleOptions or provide one when constructing a ChronicleClient.

The ChronicleConnectionString.Development constant provides a pre-configured development connection string. Default constructors also use this value:

public static class ConnectionStringsDevelopmentDefaults
{
public static ChronicleClient Create()
{
var options = new ChronicleOptions();
return new ChronicleClient(options);
}
}

This is equivalent to:

using Cratis.Chronicle.Connections;
public static class ConnectionStringsDevelopmentDefaultsEquivalent
{
public static ChronicleClient CreateFromOptions()
{
var options = ChronicleOptions.FromDevelopmentConnectionString();
return new ChronicleClient(options);
}
public static ChronicleClient CreateFromConnectionString() => new(ChronicleConnectionString.Development);
}

Use explicit configuration for production environments.

public static class ConnectionStringsFromConnectionString
{
public static ChronicleClient Create()
{
var options = ChronicleOptions.FromConnectionString("chronicle://localhost:35000");
return new ChronicleClient(options);
}
}

Use ChronicleConnectionStringBuilder to construct a connection string programmatically:

using Cratis.Chronicle.Connections;
public static class ConnectionStringsFluentBuilder
{
public static ChronicleClient Create()
{
var connectionString = new ChronicleConnectionStringBuilder()
.WithHost("server.example.com")
.WithPort(35000)
.WithCredentials("clientId", "clientSecret")
.Build();
var options = ChronicleOptions.FromConnectionString(connectionString);
return new ChronicleClient(options);
}
}

A connection string carries the client secret, the API key and the certificate password, so it must never be written to a log or an error message as it stands. ChronicleConnectionString.Redacted renders it with every credential replaced by REDACTED, while keeping the parts that make a log entry useful — scheme, host, port and the non-sensitive options:

using Cratis.Chronicle.Connections;
public static class ConnectionStringsRedactingForLogs
{
public static void LogConnectionTarget(ILogger logger)
{
var connectionString = new ChronicleConnectionString("chronicle://clientId:clientSecret@server.example.com:35000");
// Logs: chronicle://clientId:REDACTED@server.example.com:35000
logger.LogInformation("Connecting to {RedactedConnectionString}", connectionString.Redacted);
}
}

ToString() still renders the connection string in full, credentials included. Use it to pass the value on, never to report it.

The client uses Redacted for its own log messages, so connecting no longer writes the client secret to the log.

You cannot specify both client credentials and API key authentication in the same connection string. Doing so throws an AmbiguousAuthenticationMode error.