Logging

    Configuring logging with the .NET Operational Insights SDK.

    The .NET Operational Insights SDK emits log messages that can help with troubleshooting.

    Logging

    An ILoggerFactory can be provided to the ClusterOptions when creating a Cluster.

    Example 1. Using Serilog

    Using Serilog and wiring it to the SDK’s Microsoft.Extensions.Logging API:

    Add the following dependencies to your project, as required:

    <PackageReference Include="Microsoft.Extensions.Logging" />
    <PackageReference Include="Serilog" />
    <PackageReference Include="Serilog.Extensions.Logging" />
    <PackageReference Include="Serilog.Sinks.Console" />
    <PackageReference Include="Serilog.Sinks.File" />
    Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Is(LogEventLevel.Debug)
        .Enrich.FromLogContext()
        .WriteTo.Console()
        .WriteTo.File(
            path: "Logs/my-logs.log",
            rollingInterval: RollingInterval.Day,
            shared: true)
        .CreateLogger();
    
    var loggerFactory = LoggerFactory.Create(builder =>
    {
        builder.ClearProviders();
        builder.AddSerilog();
    });
    
    var clusterOptions = new ClusterOptions().WithLogging(loggerFactory);
    
    var credential = Credential.Create("username", "password");
    
    var cluster = Cluster.Create(
        connectionString: "https://insights.my-couchbase.example.com:18095",
        credential: credential,
        clusterOptions: clusterOptions
    );
    Using minimal logging without 3rd party sinks
    var loggerFactory = LoggerFactory.Create(builder =>
    {
        builder.ClearProviders();
        builder.SetMinimumLevel(LogLevel.Debug);
        builder.AddConsole();
    });