Search Results for

    Show / Hide Table of Contents

    Class NLogFactory

    The default actionETL logging factory implementation, using NLog for the logging, that the worker system use if no logging factory is injected into it. Use this class to create your own log factory instance, which can be injected into worker systems, and/or used outside worker systems.

    Also see NLogDisposableFactory, which handles the scenarios where the logging factory must be disposed after use.

    Inheritance
    Object
    NLogFactory
    NLogDisposableFactory
    Implements
    IALogFactory
    Namespace: actionETL.Logging.NLogExternal
    Assembly: actionETL.dll
    Syntax
    public class NLogFactory : IALogFactory

    Constructors

    NLogFactory(LogFactory)

    Initializes a new instance of the NLogFactory class.

    Declaration
    public NLogFactory(LogFactory logFactory)
    Parameters
    Type Name Description
    NLog.LogFactory logFactory

    The NLog log factory.

    Exceptions
    Type Condition
    ArgumentNullException

    logFactory

    Properties

    Configuration

    Gets or sets the current logging configuration. After setting this property, all existing loggers will be re-configured, so there is no need to call ReconfigExistingLoggers() manually.

    This property is thread-safe.

    Declaration
    public LoggingConfiguration Configuration { get; set; }
    Property Value
    Type Description
    NLog.Config.LoggingConfiguration

    The configuration.

    Methods

    CreateDefaultConfiguration()

    Create a default NLog logging configuration that logs to a file (e.g. "MyProcessName.log"), and to the console. This can be further modified and passed to Create(LoggingConfiguration).

    Also see the GetSingleton() overloads.

    This method is thread-safe.

    Declaration
    public static LoggingConfiguration CreateDefaultConfiguration()
    Returns
    Type Description
    NLog.Config.LoggingConfiguration

    A default NLog logging configuration.

    Flush()

    Flushes any pending log messages (in case of asynchronous targets) with the default timeout of 15 seconds.

    This method is thread-safe.

    Declaration
    public void Flush()

    Flush(Int32)

    Flushes any pending log messages (in case of asynchronous targets).

    This method is thread-safe.

    Declaration
    public void Flush(int timeoutMilliseconds)
    Parameters
    Type Name Description
    Int32 timeoutMilliseconds

    Maximum time to allow for the flush. Any messages after that time will be discarded.

    GetLogger(String)

    Gets a logger.

    This method is thread-safe.

    Underlying NLog loggers are cached (if there is sufficient memory available) and in general only one underlying NLog logger per loggerName and NLogFactory combination exists.

    When creating hundreds of thousands of workers iteratively, do reuse the same names (and Locator strings) for successive workers if possible, to allow reusing loggers and reduce the overhead of creating new loggers.

    Declaration
    public ALog GetLogger(string loggerName)
    Parameters
    Type Name Description
    String loggerName

    Name of the logger.

    Returns
    Type Description
    ALog

    A logger with the specified logger name.

    GetLogger(Type)

    Gets the logger.

    This method is thread-safe.

    Underlying NLog loggers are cached (if there is sufficient memory available) and in general only one underlying NLog logger per loggerName and NLogFactory combination exists.

    When creating hundreds of thousands of workers iteratively, do reuse the same names (and Locator strings) for successive workers if possible, to allow reusing loggers and reduce the overhead of creating new loggers.

    Declaration
    public ALog GetLogger(Type type)
    Parameters
    Type Name Description
    Type type

    The type whose name becomes the logger name.

    Returns
    Type Description
    ALog

    A logger with the logger name taken from the type name.

    Exceptions
    Type Condition
    ArgumentNullException

    type

    GetSingleton()

    Gets (or creates) a singleton NLog logging factory (using NLog.LogManager), which is application wide and shared with other logging factories acquiring this singleton factory.

    If no configuration file is found in the standard locations, a default configuration (see CreateDefaultConfiguration()) is created and applied to the singleton logging factory. Note that this will change the configuration for all users of the singleton factory.

    This method is thread-safe.

    Declaration
    public static NLogFactory GetSingleton()
    Returns
    Type Description
    NLogFactory

    A singleton logging factory.

    GetSingleton(Boolean)

    Gets (or creates) a singleton NLog logging factory (using NLog.LogManager), which is application wide and shared with other logging factories acquiring this singleton factory.

    This method is thread-safe.

    Declaration
    public static NLogFactory GetSingleton(bool requireConfigurationFile)
    Parameters
    Type Name Description
    Boolean requireConfigurationFile

    If set to true, and no configuration file is found in the standard locations, throw an exception. If set to false, and no configuration file is found in the standard locations, a default configuration (see CreateDefaultConfiguration()) is created and applied to the singleton logging factory. Note that this will change the configuration for all users of the singleton factory.

    Returns
    Type Description
    NLogFactory

    A singleton logging factory.

    Exceptions
    Type Condition
    InvalidOperationException

    No NLog logging configuration file found.

    ReconfigExistingLoggers()

    Loops through all loggers previously returned by GetLogger() overloads and recalculates their target and filter list. Useful after modifying the configuration programmatically to ensure that all loggers have been properly configured.

    This method is thread-safe.

    Declaration
    public void ReconfigExistingLoggers()

    Implements

    IALogFactory

    See Also

    NLogDisposableFactory
    IALogFactory
    In This Article
    Back to top Copyright © 2023 Envobi Ltd