LaunchDarkly Dotnet Server SDK
Search Results for

    Show / Hide Table of Contents

    Class LoggingConfigurationBuilder

    Contains methods for configuring the SDK's logging behavior.

    Inheritance
    object
    LoggingConfigurationBuilder
    Implements
    IComponentConfigurer<LoggingConfiguration>
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: LaunchDarkly.Sdk.Server.Integrations
    Assembly: LaunchDarkly.ServerSdk.dll
    Syntax
    public sealed class LoggingConfigurationBuilder : IComponentConfigurer<LoggingConfiguration>
    Remarks

    If you want to set non-default values for any of these properties, create a builder with Logging(), change its properties with the methods of this class, and pass it to Logging(IComponentConfigurer<LoggingConfiguration>).

    By default, the SDK has the following logging behavior:

    • Log messages are written to standard output. To change this, use a log adapter as described in Adapter(ILogAdapter) and Logging(ILogAdapter).
    • The lowest enabled log level is Info, so Debug messages are not shown. To change this, use Level(LogLevel).
    • The base logger name is LaunchDarkly.Sdk. See BaseLoggerName(string) for more about logger names and how to change the name.
    Examples
    var config = Configuration.Builder("my-sdk-key")
        .Logging(Components.Logging().Level(LogLevel.Warn))
        .Build();

    Constructors

    | Edit this page View Source

    LoggingConfigurationBuilder()

    Creates a new builder with default properties.

    Declaration
    public LoggingConfigurationBuilder()

    Fields

    | Edit this page View Source

    DefaultLogDataSourceAsErrorAfter

    The default value for LogDataSourceOutageAsErrorAfter(TimeSpan?): one minute.

    Declaration
    public static readonly TimeSpan DefaultLogDataSourceAsErrorAfter
    Field Value
    Type Description
    TimeSpan

    Methods

    | Edit this page View Source

    Adapter(ILogAdapter)

    Specifies the implementation of logging to use.

    Declaration
    public LoggingConfigurationBuilder Adapter(ILogAdapter adapter)
    Parameters
    Type Name Description
    ILogAdapter adapter

    an ILogAdapter for the desired logging implementation

    Returns
    Type Description
    LoggingConfigurationBuilder

    the same builder

    Remarks

    The LaunchDarkly.Logging API defines the ILogAdapter interface to specify where log output should be sent. By default, it is set to Logs.ToConsole, meaning that output will be sent to Console.Error. You may use other LaunchDarkly.Logging.Logs methods, or a custom implementation, to handle log output differently. For instance, in .NET Core, specify Logs.CoreLogging to use the standard .NET Core logging framework.

    For more about logging adapters, see the SDK reference guide, the API documentation for LaunchDarkly.Logging, and the third-party adapters that LaunchDarkly provides (you can also create your own adapter using the LaunchDarkly.Logging API).

    If you don't need to customize any options other than the adapter, you can call Logging(ILogAdapter) as a shortcut rather than using LoggingConfigurationBuilder.

    Examples
    // This example configures the SDK to use the standard .NET Core log framework
    // (Microsoft.Extensions.Logging).
    var config = Configuration.Builder("my-sdk-key")
        .Logging(Components.Logging().Adapter(Logs.CoreLogging(coreLoggingFactory)))
        .Build();
    | Edit this page View Source

    BaseLoggerName(string)

    Specifies a custom base logger name.

    Declaration
    public LoggingConfigurationBuilder BaseLoggerName(string baseLoggerName)
    Parameters
    Type Name Description
    string baseLoggerName
    Returns
    Type Description
    LoggingConfigurationBuilder
    Remarks

    Logger names are used to give context to the log output, indicating that it is from the LaunchDarkly SDK instead of another component, or indicating a more specific area of functionality within the SDK. The default console logging implementation shows the logger name in brackets, for instance:

    [LaunchDarkly.Sdk.DataSource] INFO: Reconnected to LaunchDarkly stream

    If you are using an adapter for a third-party logging framework such as NUnit (see Adapter(ILogAdapter)), most frameworks have a mechanism for filtering log output by the logger name.

    By default, the SDK uses a base logger name of LaunchDarkly.Sdk. Messages will be logged either under this name, or with a suffix to indicate what general area of functionality is involved:

    • .DataSource: problems or status messages regarding how the SDK gets feature flag data from LaunchDarkly.
    • .DataStore: problems or status messages regarding how the SDK stores its feature flag data (for instance, if you are using a database).
    • .Evaluation: problems in evaluating a feature flag or flags, which were caused by invalid flag data or incorrect usage of the SDK rather than for instance a database problem.
    • .Events problems or status messages regarding the SDK's delivery of analytics event data to LaunchDarkly.

    Setting BaseLoggerName to a non-null value overrides the default. The SDK still adds the same suffixes to the name, so for instance if you set it to "LD", the example message above would show [LD.DataSource].

    | Edit this page View Source

    Build(LdClientContext)

    Called internally by the SDK to create an implementation instance. Applications should not need to call this method.

    Declaration
    public LoggingConfiguration Build(LdClientContext context)
    Parameters
    Type Name Description
    LdClientContext context

    provides configuration properties and other components from the current SDK client instance

    Returns
    Type Description
    LoggingConfiguration

    a instance of the component type

    | Edit this page View Source

    Level(LogLevel)

    Specifies the lowest level of logging to enable.

    Declaration
    public LoggingConfigurationBuilder Level(LogLevel minimumLevel)
    Parameters
    Type Name Description
    LogLevel minimumLevel

    the lowest level of logging to enable

    Returns
    Type Description
    LoggingConfigurationBuilder

    the same builder

    Remarks

    This adds a log level filter that is applied regardless of what implementation of logging is being used, so that log messages at lower levels are suppressed. For instance, setting the minimum level to Info means that Debug-level output is disabled. External logging frameworks may also have their own mechanisms for setting a minimum log level.

    If you did not specify an ILogAdapter at all, so it is using the default Console.Error destination, then the default minimum logging level is Info.

    If you did specify an ILogAdapter, then the SDK does not apply a level filter by default. This is so as not to interfere with any other configuration that you may have set up in an external logging framework. However, you can still use this method to set a higher level so that any messages below that level will not be sent to the external framework at all.

    | Edit this page View Source

    LogDataSourceOutageAsErrorAfter(TimeSpan?)

    Sets the time threshold, if any, after which the SDK will log a data source outage at Error level instead of Warn level.

    Declaration
    public LoggingConfigurationBuilder LogDataSourceOutageAsErrorAfter(TimeSpan? interval)
    Parameters
    Type Name Description
    TimeSpan? interval

    the error logging threshold, or null

    Returns
    Type Description
    LoggingConfigurationBuilder

    the same builder

    Remarks

    A data source outage means that an error condition, such as a network interruption or an error from the LaunchDarkly service, is preventing the SDK from receiving feature flag updates. Many outages are brief and the SDK can recover from them quickly; in that case it may be undesirable to log an Error line, which might trigger an unwanted automated alert depending on your monitoring tools. So, by default, the SDK logs such errors at Warn level. However, if the amount of time specified by this method elapses before the data source starts working again, the SDK will log an additional message at Error level to indicate that this is a sustained problem.

    The default is DefaultLogDataSourceAsErrorAfter. Setting it to null will disable this feature, so you will only get Warn messages.

    Implements

    IComponentConfigurer<T>
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX