Show / Hide Table of Contents

    Class LoggingExtensions

    Extensions class for logging.

    Inheritance
    Object
    LoggingExtensions
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Microsoft.Graph.Communications.Common.Telemetry
    Assembly: Microsoft.Graph.Communications.Common.dll
    Syntax
    public static class LoggingExtensions

    Methods

    BindToILoggerFactory(GraphLogger, ILoggerFactory, ILogEventFormatter)

    Bind to ILogger

    Declaration
    public static Observer<LogEvent> BindToILoggerFactory(this GraphLogger graphLogger, ILoggerFactory loggerFactory, ILogEventFormatter formatter = null)
    Parameters
    Type Name Description
    GraphLogger graphLogger

    The graph logger

    ILoggerFactory loggerFactory

    The ILogger

    ILogEventFormatter formatter

    The message formatter

    Returns
    Type Description
    Observer<LogEvent>

    The observer of graph logger

    Concat(IReadOnlyDictionary<Type, Object>, IEnumerable<Object>)

    Get the merged propertied.

    Declaration
    public static IReadOnlyDictionary<Type, object> Concat(this IReadOnlyDictionary<Type, object> properties, IEnumerable<object> additionalProperties)
    Parameters
    Type Name Description
    IReadOnlyDictionary<Type, Object> properties

    The property collection.

    IEnumerable<Object> additionalProperties

    The additional property collection.

    Returns
    Type Description
    IReadOnlyDictionary<Type, Object>

    The merged property collection.

    CreateILogger(IGraphLogger, String, Guid, LogEventType, IEnumerable<Object>)

    Creates the ILogger interface from Logging abstractions.

    Declaration
    public static ILogger CreateILogger(this IGraphLogger logger, string component = null, Guid correlationId = default(Guid), LogEventType eventType = LogEventType.Trace, IEnumerable<object> properties = null)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String component

    The component for which log is created.

    Guid correlationId

    The correlation identifier.

    LogEventType eventType

    Log event type

    IEnumerable<Object> properties

    Extra properties for the log event

    Returns
    Type Description
    ILogger

    The ILogger interface.

    CreateShim(IGraphLogger, String, Nullable<Guid>, IEnumerable<Object>, ObfuscationConfiguration)

    Creates the shim graph logger. The shim IGraphLogger wraps this logger and appends the specified content to each log request.

    Declaration
    public static IGraphLogger CreateShim(this IGraphLogger logger, string component = null, Guid? correlationId = default(Guid? ), IEnumerable<object> properties = null, ObfuscationConfiguration obfuscationConfiguration = null)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String component

    The component for which log is created.

    Nullable<Guid> correlationId

    The correlation identifier.

    IEnumerable<Object> properties

    Extra properties for the log event

    ObfuscationConfiguration obfuscationConfiguration

    The obfuscation configuration.

    Returns
    Type Description
    IGraphLogger

    The IGraphLogger shim.

    EnterMethod(IGraphLogger, Guid, String, String, Int32)

    Log for entering method.

    Declaration
    public static LogEvent EnterMethod(this IGraphLogger logger, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Error(IGraphLogger, Exception, String, String, Guid, String, String, Int32)

    Log exceptions with error level.

    Declaration
    public static LogEvent Error(this IGraphLogger logger, Exception exception, string message = "", string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Exception exception

    Exception information.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Error(IGraphLogger, String, String, Guid, String, String, Int32)

    Log messages with error level.

    Declaration
    public static LogEvent Error(this IGraphLogger logger, string message, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Flatten(IReadOnlyDictionary<Type, Object>, IEnumerable<Type>, IEnumerable<PropertyInfo>)

    Get the flatten key-value pairs for the properties of LogEvent.

    Declaration
    public static IEnumerable<KeyValuePair<string, object>> Flatten(this IReadOnlyDictionary<Type, object> properties, IEnumerable<Type> ignoreTypes = null, IEnumerable<PropertyInfo> ignoreSubProperties = null)
    Parameters
    Type Name Description
    IReadOnlyDictionary<Type, Object> properties

    The properties

    IEnumerable<Type> ignoreTypes

    The types in this list will be ingored

    IEnumerable<PropertyInfo> ignoreSubProperties

    The property members of specific types in this list will be ingored

    Returns
    Type Description
    IEnumerable<KeyValuePair<String, Object>>

    The flattern result.

    Remarks

    The primitive types and types implemented IEnumerable (string, list, dictionary, etc) will keep original value. The flatten support one level property lookup only.

    GetHeaderText(IGraphLogger, IEnumerable<KeyValuePair<String, IEnumerable<String>>>)

    Logs the headers text.

    Declaration
    public static IEnumerable<string> GetHeaderText(this IGraphLogger logger, IEnumerable<KeyValuePair<string, IEnumerable<string>>> headers)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    IEnumerable<KeyValuePair<String, IEnumerable<String>>> headers

    The headers.

    Returns
    Type Description
    IEnumerable<String>

    Log Text

    GetTypedProperties(LogEvent, Type)

    Gets the client common properties from log event.

    Declaration
    public static object GetTypedProperties(this LogEvent logEvent, Type type)
    Parameters
    Type Name Description
    LogEvent logEvent

    The log event.

    Type type

    The type of the property.

    Returns
    Type Description
    Object

    The client common properties.

    GetTypedProperty<T>(LogEvent)

    Gets the client common properties from log event.

    Declaration
    public static T GetTypedProperty<T>(this LogEvent logEvent)
    
        where T : class
    Parameters
    Type Name Description
    LogEvent logEvent

    The log event.

    Returns
    Type Description
    T

    The client common properties.

    Type Parameters
    Name Description
    T

    The property type.

    Info(IGraphLogger, String, String, Guid, String, String, Int32)

    Log exceptions with info level.

    Declaration
    public static LogEvent Info(this IGraphLogger logger, string message, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    LeaveMethod(IGraphLogger, Guid, String, String, Int32)

    Log for leaving method.

    Declaration
    public static LogEvent LeaveMethod(this IGraphLogger logger, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Log(IGraphLogger, TraceLevel, Exception, String, String, Guid, String, String, Int32)

    Log exceptions.

    Declaration
    public static LogEvent Log(this IGraphLogger logger, TraceLevel level, Exception exception, string message = null, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    TraceLevel level

    The trace level.

    Exception exception

    Exception information.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    LogHttpMessage(IGraphLogger, TraceLevel, TransactionDirection, HttpTraceType, String, String, String, IEnumerable<KeyValuePair<String, IEnumerable<String>>>, Int32, String, Nullable<Int64>, Guid, Guid, String, String, Int32)

    Logs the http message.

    Declaration
    public static LogEvent LogHttpMessage(this IGraphLogger logger, TraceLevel level, TransactionDirection direction, HttpTraceType traceType, string url, string method, string obfuscatedContent, IEnumerable<KeyValuePair<string, IEnumerable<string>>> headers, int responseCode = 200, string component = null, long? responseTime = default(long? ), Guid correlationId = default(Guid), Guid requestId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    TraceLevel level

    The trace level.

    TransactionDirection direction

    The direction for request.

    HttpTraceType traceType

    Type of the http trace.

    String url

    The URL.

    String method

    The method.

    String obfuscatedContent

    The obfuscatedContent.

    IEnumerable<KeyValuePair<String, IEnumerable<String>>> headers

    The headers.

    Int32 responseCode

    The response code. (used only if [traceType == HttpResponse])

    String component

    The component in which log is created.

    Nullable<Int64> responseTime

    The response time. (used only if [traceType == HttpResponse])

    Guid correlationId

    The correlation identifier.

    Guid requestId

    The message identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object

    Metric(IGraphLogger, String, String, Int64, Dictionary<String, String>, Boolean, String, Guid, String, String, Int32)

    Log metrics

    Declaration
    public static LogEvent Metric(this IGraphLogger logger, string metricNamespace, string metricName, long rawData, Dictionary<string, string> dimensions, bool addDefaultDimension = true, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String metricNamespace

    Metric namespace

    String metricName

    Metric name

    Int64 rawData

    Raw data

    Dictionary<String, String> dimensions

    Dimension name-value dictionary

    Boolean addDefaultDimension

    Indicates whether adds default dimension

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Obfuscate(IGraphLogger, Object, ObfuscationTag)

    Obfuscates the specified payload with the tag.

    Declaration
    public static string Obfuscate(this IGraphLogger logger, object payload, ObfuscationTag obfuscationTag)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Object payload

    The payload.

    ObfuscationTag obfuscationTag

    The obfuscation tag.

    Returns
    Type Description
    String

    Obfuscated data

    SerializeAndObfuscate(IGraphLogger, Object, Formatting)

    Serializes the payload and obfuscates it.

    Declaration
    public static string SerializeAndObfuscate(this IGraphLogger logger, object payload, Formatting formatting)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Object payload

    The payload.

    Newtonsoft.Json.Formatting formatting

    The formatting.

    Returns
    Type Description
    String

    Obfuscated data.

    ToLogLevel(TraceLevel)

    Get log level from trace level.

    Declaration
    public static LogLevel ToLogLevel(this TraceLevel level)
    Parameters
    Type Name Description
    TraceLevel level

    The trace level

    Returns
    Type Description
    LogLevel

    The log level

    ToTraceLevel(LogLevel)

    Gets the tracelevel for log level.

    Declaration
    public static TraceLevel ToTraceLevel(this LogLevel logLevel)
    Parameters
    Type Name Description
    LogLevel logLevel

    The log level.

    Returns
    Type Description
    TraceLevel

    trace level

    Verbose(IGraphLogger, String, String, Guid, String, String, Int32)

    Log verbose level.

    Declaration
    public static LogEvent Verbose(this IGraphLogger logger, string message, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Warn(IGraphLogger, Exception, String, String, Guid, String, String, Int32)

    Log exceptions with warning level.

    Declaration
    public static LogEvent Warn(this IGraphLogger logger, Exception exception, string message = "", string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    Exception exception

    Exception information.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Warn(IGraphLogger, String, String, Guid, String, String, Int32)

    Log exceptions with warning level.

    Declaration
    public static LogEvent Warn(this IGraphLogger logger, string message, string component = null, Guid correlationId = default(Guid), string memberName = null, string filePath = null, int lineNumber = 0)
    Parameters
    Type Name Description
    IGraphLogger logger

    The logger.

    String message

    The message.

    String component

    The component in which log is created

    Guid correlationId

    The correlation identifier.

    String memberName

    Calling function.

    String filePath

    File name where code is located.

    Int32 lineNumber

    Line number where code is located.

    Returns
    Type Description
    LogEvent

    Log Event object.

    Back to top Copyright (c) Microsoft Corporation. All rights reserved.