Wolfringo Wolfringo
Wolfringo Wolfringo
Wolfringo (c) 2020 TehGM
DocFX, DiscordFX theme.
Search Results for

    Class ExceptionLoggingHelper

    Utility class for logging exceptions.

    Inheritance
    System.Object
    ExceptionLoggingHelper
    Namespace: TehGM.Wolfringo.Utilities
    Assembly: Wolfringo.Core.dll
    Syntax
    public static class ExceptionLoggingHelper
    Remarks

    By default, if exception is caught, and exception is logged inside of the handling block, the log scope will be lost. The way around this is to log the exception using `when` keyword.
    This class contains methods that return true so they can be used with `when` syntax.

    Usage sample:

    try
    {
        // ...
    }
    catch (Exception ex) when (ex.LogAsError(_log, "Exception has occured")) { }

    More information: https://andrewlock.net/how-to-include-scopes-when-logging-exceptions-in-asp-net-core/#exceptions-inside-scope-blocks-lose-the-scope

    Methods

    | Improve this Doc View Source

    LogAsCritical(Exception, ILogger, String, Object[])

    Logs exception with critical log level.

    Declaration
    public static bool LogAsCritical(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.

    | Improve this Doc View Source

    LogAsDebug(Exception, ILogger, String, Object[])

    Logs exception with debug log level.

    Declaration
    public static bool LogAsDebug(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.

    | Improve this Doc View Source

    LogAsError(Exception, ILogger, String, Object[])

    Logs exception with error log level.

    Declaration
    public static bool LogAsError(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.

    | Improve this Doc View Source

    LogAsInformation(Exception, ILogger, String, Object[])

    Logs exception with information log level.

    Declaration
    public static bool LogAsInformation(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.

    | Improve this Doc View Source

    LogAsTrace(Exception, ILogger, String, Object[])

    Logs exception with trace log level.

    Declaration
    public static bool LogAsTrace(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.

    | Improve this Doc View Source

    LogAsWarning(Exception, ILogger, String, Object[])

    Logs exception with warning log level.

    Declaration
    public static bool LogAsWarning(this Exception exception, ILogger log, string message, params object[] args)
    Parameters
    Type Name Description
    System.Exception exception

    Exception message to log.

    Microsoft.Extensions.Logging.ILogger log

    Logger instance.

    System.String message

    Log message template.

    System.Object[] args

    Structured log message arguments.

    Returns
    Type Description
    System.Boolean

    Always returns true.

    Remarks

    See ExceptionLoggingHelper for more information.

    This method is null-logger-safe - if log is null, message and exception won't be logged.