LaunchDarkly Dotnet Client SDK
Search Results for

    Show / Hide Table of Contents

    Class LogValues

    Helper methods for logging special variables.

    Inheritance
    object
    LogValues
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: LaunchDarkly.Logging
    Assembly: LaunchDarkly.Logging.dll
    Syntax
    public static class LogValues

    Methods

    Defer(Func<string>)

    Converts any function that returns a string into an object for calling it lazily.

    Declaration
    public static object Defer(Func<string> stringProvider)
    Parameters
    Type Name Description
    Func<string> stringProvider

    a function that returns a string

    Returns
    Type Description
    object

    an object that calls that function if ToString() is called

    Remarks

    Sometimes log messages may include a computed value that has enough computational overhead that you would prefer not to compute it unless it really will be logged. The Logger methods that take parameters of type object do not call ToString() to convert those parameters to strings immediately; if logging of this message has been disabled by a Level(ILogAdapter, LogLevel) filter, or some other filtering mechanism defined by the log adapter, or if all logging is disabled because the destination is None, then ToString() is not called. The object returned by Defer simply delegates its ToString() method to the function you provide.

    Examples

    // Here, ComputeJSONData is only called if debug-level logging is enabled logger.Debug("The JSON data is: {0}", () => ComputeJSONData());

    ExceptionSummary(Exception)

    Returns an object that lazily constructs a basic exception description.

    Declaration
    public static object ExceptionSummary(Exception e)
    Parameters
    Type Name Description
    Exception e

    an exception

    Returns
    Type Description
    object

    an object whose ToString() method provides a description

    Remarks

    Calling ToString() on the object returned by this method returns a string that includes the name of the exception class, its Message (if any), and the same properties for its InnerException (if any). This string is not constructed unless ToString() is called, so writing exceptions to the log in this way incurs very little overhead if logging is not enabled for the specified log level.

    Examples

    try { ... } catch (Exception e) { logger.Debug("Caught: {0} {1}", LogValues.ExceptionSummary(e), LogValues.ExceptionTrace(e)); }

    ExceptionTrace(Exception)

    Returns an object that lazily constructs an exception stacktrace.

    Declaration
    public static object ExceptionTrace(Exception e)
    Parameters
    Type Name Description
    Exception e

    an exception

    Returns
    Type Description
    object

    an object whose ToString() method provides a stacktrace

    Remarks

    Calling ToString() on the object returned by this method returns the exception's stacktrace as a string. This string is not constructed unless ToString() is called, so writing exceptions to the log in this way incurs very little overhead if logging is not enabled for the specified log level.

    Examples

    try { ... } catch (Exception e) { logger.Debug("Caught: {0} {1}", LogValues.ExceptionSummary(e), LogValues.ExceptionTrace(e)); }

    In this article
    Back to top Generated by DocFX