Show / Hide Table of Contents

Class Logs

Factory methods for the basic logging implementations in this package.

Inheritance
System.Object
Logs
Namespace: LaunchDarkly.Logging
Assembly: LaunchDarkly.Logging.dll
Syntax
public static class Logs : Object
Remarks

See ILogAdapter for more about how LaunchDarkly.Logging works with different implementations of logging. The methods and properties in Logs provide easy access to basic behaviors like logging to the console or to a file, or capturing log output for testing; if you need to direct the log output to another logging framework that your application is using, you will use an ILogAdapter implementation specific to that framework instead.

Properties

Default

A default implementation that writes to the standard error stream at Info level.

Declaration
public static ILogAdapter Default { get; }
Property Value
Type Description
ILogAdapter
Remarks

This simply calls ToConsole, and then uses Level(ILogAdapter, LogLevel) to set the minimum level to Info (that is, it suppresses Debug logging).

None

A stub that generates no log output.

Declaration
public static ILogAdapter None { get; }
Property Value
Type Description
ILogAdapter

ToConsole

A simple logging implementation that writes to the standard error stream.

Declaration
public static SimpleLogging ToConsole { get; }
Property Value
Type Description
SimpleLogging
Remarks

This is equivalent to Logs.ToWriter(Console.Error).

By default, all logging is enabled including Debug level. To filter by level, use Level(ILogAdapter, LogLevel). You can also use SimpleLogging methods for additional configuration.

Methods

Capture()

A logging implementation that captures log messages in memory.

Declaration
public static LogCapture Capture()
Returns
Type Description
LogCapture

a LogCapture instance

CoreLogging(ILoggerFactory)

A logging implementation that delegates to the .NET Core logging framework.

Declaration
public static ILogAdapter CoreLogging(ILoggerFactory loggerFactory)
Parameters
Type Name Description
Microsoft.Extensions.Logging.ILoggerFactory loggerFactory

the factory object for .NET Core logging

Returns
Type Description
ILogAdapter

a logging adapter

Remarks

This method is only available when your target framework is .NET Core or .NET 6.0+. It causes the LaunchDarkly.Logging APIs to delegate to the Microsoft.Extensions.Logging framework. The ILoggingFactory is the main configuration object for Microsoft.Extensions.Logging; application code can construct it programmatically, or can obtain it by dependency injection. For more information, see Logging in .NET Core and ASP.NET Core.

If you want to use Microsoft.Extensions.Logging on a different platform, such as .NET Framework or a mobile OS, use the separate package LaunchDarkly.Logging.Microsoft. The adapter is not built into LaunchDarkly.Logging on those platforms, to avoid bringing in the Microsoft.Extensions.Logging package as a dependency that may not be wanted.

The .NET Core logging framework has its own mechanisms for filtering log output by level or other criteria. If you add a level filter with Level(ILogAdapter, LogLevel), it will filter out messages below that level before they reach the .NET Core logger.

ToMethod(Action<String>)

A simple logging implementation that calls a method or lambda that you specify for each line of output.

Declaration
public static SimpleLogging ToMethod(Action<string> writeLineMethod)
Parameters
Type Name Description
System.Action<System.String> writeLineMethod

a method or lambda that takes a line of text as a parameter

Returns
Type Description
SimpleLogging

a configurable logging adapter

Remarks

Each line is preformatted to include the logger name, the log level, and a timestamp (unless you disable timestamps with DateFormat(String)), in the same format used by ToConsole.

By default, all logging is enabled including Debug level. To filter by level, use Level(ILogAdapter, LogLevel). You can also use SimpleLogging methods for additional configuration.

Examples

// A silly example that just writes lines to the console, but with a "HEY!" prefix. var logAdapter = Logs.ToMethod(line => { Console.WriteLine("HEY! " + line); });

ToMultiple(ILogAdapter[])

A logging implementation that delegates to any number of destinations.

Declaration
public static ILogAdapter ToMultiple(params ILogAdapter[] logAdapters)
Parameters
Type Name Description
ILogAdapter[] logAdapters
Returns
Type Description
ILogAdapter

an ILogAdapter

Examples

// Send log output both to Console.Error and a file var fileWriter = new StreamWriter("output.log"); var logAdapter = MultiLog.Adapter( SimpleLog.Adapter, // writes to Console.Error

ToWriter(TextWriter)

A simple logging implementation that writes to any TextWriter.

Declaration
public static SimpleLogging ToWriter(TextWriter stream)
Parameters
Type Name Description
System.IO.TextWriter stream

the destination for output

Returns
Type Description
SimpleLogging

a configurable logging adapter

Remarks

This could be a built-in writer such as Console.Out, or a file.

By default, all logging is enabled including Debug level. To filter by level, use Level(ILogAdapter, LogLevel). You can also use SimpleLogging methods for additional configuration.

In This Article
Back to top Generated by DocFX