Table of Contents

Logging

The Bluesky agent provides logging through the standard .NET logging interface.

The log messages come in three categories, the BlueskyAgent category for operations specific to Bluesky, such as reading the timeline, the AtProtoAgent category for operations which are not Bluesky specific and could be used against any AT Proto server, and the DirectoryAgent category for operations performed by the DirectoryAgent class for any DID PLC Directory operations.

To configure a LoggerFactory for the agent, set the LoggerFactory property in the AtProtoAgentOptions when creating an agent.

Configuring logging

The following code illustrates using the console logger to log messages from an AtProtoAgent.

// Setup console logging, and configure the log level to Information
using ILoggerFactory loggerFactory = LoggerFactory.Create(configure =>
{
    configure.AddConsole();
    configure.SetMinimumLevel(LogLevel.Debug);
});

using var agent = new BlueskyAgent(
    options: new BlueskyAgentOptions()
    {
        LoggerFactory = loggerFactory
    });

await agent.Login(handle, password);
await agent.Logout();
Important

Depending on the regulatory environment you are working under logs may contain personal information such as a user's DID. Make sure your logs are secured appropriately.

Warning

Some log messages include values received from remote services or request-controlled input. If a logger writes these values verbatim to simple, line-oriented text logs, control characters such as newlines can make entries confusing or appear to add forged log lines. This is a limitation of that text-logging approach, not a defect in the library. For production, choose a production-quality logger that safely handles untrusted values, preferably using structured logging rather than plain text.