Contains methods for configuring the SDK's logging behavior.
public sealed class LoggingConfigurationBuilder : Object, ILoggingConfigurationFactory
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(ILoggingConfigurationFactory).
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 LaunchDarkly.Logging.LogLevel.Info, so LaunchDarkly.Logging.LogLevel.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.
var config = Configuration.Builder("my-sdk-key") .Logging(Components.Logging().Level(LogLevel.Warn)) .Build();
Creates a new builder with default properties.
The default value for LogDataSourceOutageAsErrorAfter(Nullable<TimeSpan>): one minute.
public static readonly TimeSpan DefaultLogDataSourceAsErrorAfter
Specifies the implementation of logging to use.
public LoggingConfigurationBuilder Adapter(ILogAdapter adapter)
the same builder
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
LaunchDarkly.Logging, and the
third-party adapters that
LaunchDarkly provides (you can also create your own adapter using the
// 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();
Specifies a custom base logger name.
public LoggingConfigurationBuilder BaseLoggerName(string baseLoggerName)
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.
.Eventsproblems or status messages regarding the SDK's delivery of analytics event data to LaunchDarkly.
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
example message above would show
Called internally by the SDK to create a configuration instance. Applications do not need to call this method.
public LoggingConfiguration CreateLoggingConfiguration()
the logging configuration
Specifies the lowest level of logging to enable.
public LoggingConfigurationBuilder Level(LogLevel minimumLevel)
the lowest level of logging to enable
the same builder
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 LaunchDarkly.Logging.LogLevel.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 LaunchDarkly.Logging.ILogAdapter at all, so it is using the default
destination, then the default minimum logging level is
If you did specify an LaunchDarkly.Logging.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.
Sets the time threshold, if any, after which the SDK will log a data source outage at
level instead of
public LoggingConfigurationBuilder LogDataSourceOutageAsErrorAfter(Nullable<TimeSpan> interval)
the error logging threshold, or null
the same builder
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